GAE做IP上报

来源:互联网 发布:优化营商环境心得体会 编辑:程序博客网 时间:2024/06/10 22:23
app.yaml:application: usernameversion: 1runtime: pythonapi_version: 1handlers:- url: /fetch.pyscript: fetch.py- url: /admin.pyscript: admin.py- url: /mirror.pyscript: mirror.py- url: /script: dns.pymirror.py:#! /usr/bin/env python# coding=utf-8import osimport cgifrom google.appengine.ext import webappfrom google.appengine.ext.webapp.util import run_wsgi_appclass Mirror(webapp.RequestHandler):def get(self):self.response.headers['Content-Type'] = 'text/html; charset=utf-8'addr = cgi.escape(os.environ["REMOTE_ADDR"])self.response.out.write( \'''<html><body><pre>%s</pre></body></html>''' % addr)application = webapp.WSGIApplication([('/mirror.py', Mirror)])def main():run_wsgi_app(application)if __name__ == "__main__":main()dns.py:#! /usr/bin/env python# coding=utf-8import cgifrom google.appengine.api import usersfrom google.appengine.ext import webappfrom google.appengine.ext.webapp.util import run_wsgi_appfrom google.appengine.ext import dbclass Greeting(db.Model):content = db.StringProperty(multiline=True)date = db.DateTimeProperty(auto_now_add=True)class Store(webapp.RequestHandler):def get(self):greetings = db.GqlQuery("SELECT * FROM Greeting ORDER BY date DESC LIMIT 5")for greeting in greetings:self.response.out.write( \'''<html><body>System Info: %s<br><br></body></html>''' % cgi.escape(greeting.content))# Write the submission form and the footer of the pageself.response.out.write("""<html><body><form action="/" method="post"><div><textarea name="content" rows="3" cols="60"></textarea></div><div><input type="submit" value="Flush"></div></form></body></html>""")def post(self):greetings = db.GqlQuery("SELECT * FROM Greeting ORDER BY date DESC LIMIT 5")for result in greetings:result.delete()greeting = Greeting()greeting.content = self.request.get('content')greeting.put()self.redirect('/')application = webapp.WSGIApplication([('/', Store)])def main():run_wsgi_app(application)if __name__ == "__main__":main()

原创粉丝点击