This script is very basic: it does one thing. Connect to it's root and it will log your IP if it has never seen it before. Connect to
/logs, and it will show a list of unique IPs within the server storage. I can't take 100 percent credit for it. I grabbed it off of Stack Overflow, modified it to actually run on App Engine, and changed the save mechanism to prevent duplicate entries. This thing is so simple it's shocking; considering how many different super-elaborate ways I can waste money and time doing the same thing. I use it to keep track of my
ssh IP. I run
wget on my
App Engine address every ten minutes. Can this be improved? Are there any flaws which may compromise its efficiency?
from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app from google.appengine.ext import db class Log(db.Model): access_time = db.DateTimeProperty(auto_now_add=True) ip_address = db.StringProperty() class MainPage(webapp.RequestHandler): def get(self): ip = self.request.remote_addr log = Log() logs = Log.all() is_new = True for log in logs: if ip == log: is_new = False if is_new: log.ip_address = ip log.put() self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Logged your visit from ip address %s' % ip) class LogPage(webapp.RequestHandler): def get(self): logs = Log.all() self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Ip addresses: ') for log in logs: self.response.out.write(log.ip_address + ',') app = webapp.WSGIApplication([('/', MainPage), ('/logs', LogPage)], debug=True)
runtime: python27 api_version: 1 threadsafe: true handlers: - url: /.* script: helloworld.app
P.S. I'm pretty sure this isn't violating any contracts or agreements. Tell me if I'm wrong about that.