美文网首页
tools--tornado-agent

tools--tornado-agent

作者: amazing_bing | 来源:发表于2016-11-15 11:54 被阅读0次

    程序入口api,代码如下:

    # -*- coding: utf-8 -*-
    # 端口扫描主程序API入口
    # Author:Bing
    # Contact:amazing_bing@outlook.com
    # Date:2016.11.14
    
    import tornado.ioloop
    import tornado.web
    from core.frame import test
    import json
    
    '''
    #多参数配置
    #异步并发
    class BaseHandler(tornado.web.RequestHandler):
        def get_current_user(self):
            return self.get_secure_cookie("user")
        def post(self):
            #self.set_secure_cookie("user", self.get_argument("myname"))
            # self.write("POST LOGIN")
            self.redirect("/")
    '''
    
    class MainHandler(tornado.web.RequestHandler):
        def get(self):
            self.current_user = "hello!welcome to this portscan api index"
            name = tornado.escape.xhtml_escape(self.current_user)#tornado.escape.json_encode(self.current_user)
            self.write(name)
    
    class ScanHandler(tornado.web.RequestHandler):
        def post(self,*args,**kwargs):
            print self.request.remote_ip
            print self.request.body_arguments
            user = self.get_body_argument('user')
            respon_json = tornado.escape.json_encode(user)    
            self.write(respon_json)    
    
    class ListHandler(tornado.web.RequestHandler):
        def get(self):
            info = {'user':'leno'}
            name = json.dumps(info)
            self.write(name)
    
    class AddHandler(tornado.web.RequestHandler):
        def get(self):
            self.write("add task")
    
    class UpdHandler(tornado.web.RequestHandler):
        def get(self):
            self.write("update task")
    
    class DelHandler(tornado.web.RequestHandler):
        def get(self):
            self.write("delete task")
    
    settings = dict(
                # template_path=TEMPLATE_PATH,
                # static_path=STATIC_PATH,
                # cookie_secret=str(uuid.uuid1()),
                #cookie_secret="61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
                #login_url="/login",
                # gzip=True,
                # xheaders=True,
                # 'xsrf_cookies': True,          # 防止跨站伪造
                # 'ui_methods': mt,              # 自定义UIMethod函数
                # 'ui_modules': md,              # 自定义UIModule类
                debug=True
            )
    
    application = tornado.web.Application([
        (r"/", MainHandler),
        (r"/scan", ScanHandler),
        (r"/list", ListHandler),
        (r"/add", AddHandler),
        (r"/update", UpdHandler),
        (r"/del", DelHandler)
    ], **settings)
    
    if __name__ == "__main__":
        application.listen(8888)
        tornado.ioloop.IOLoop.current().start()
    
    

    相关文章

      网友评论

          本文标题:tools--tornado-agent

          本文链接:https://www.haomeiwen.com/subject/oigkpttx.html