程序入口api,代码如下:
# -*- coding: utf-8 -*-
# 端口扫描主程序API入口
# Author:Bing
# Contact:[email protected]
# 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()