首页 > 系统服务 > 详细

flask实现获取表单并执行shell

时间:2017-01-24 17:16:44      阅读:612      评论:0      收藏:0      [点我收藏+]
一个HTML form input和一个button提供给用户输入
flask的request获取用户输入的文件名
判断异常
执行shell命令touch aa.txt 并返回ls查看的结果
 
技术分享
技术分享
pip install flask
 
filename.py
#!/bin/env python
# _*_coding:utf-8_*_
import os
from flask import Flask
from flask import request

app = Flask(__name__)

@app.route(/, methods=[GET])
def index():
    return ‘‘‘<form action="/" method="post">
        <label>Filename:</label>
        <input name="filename">
        <input type="submit">
        </form>‘‘‘


@app.route(/, methods=[POST])
def get_sn():
    filename= request.form[filename]
    try:
        filename.encode()
    except Exception,e:
        print Exception,":",e
        return "Please check your input! like this:index.html aa.log"
    os.popen(touch  + filename).read()
    out=os.popen(ls /var/tmp).read()
    return <h3> file: <br> %s </h3> % out


if __name__ == __main__:
    app.run(host=0.0.0.0,port=5000,debug=True)

执行

python filename.py

本机浏览器localhost:5000

其他电脑:本机IP:5000

 

flask实现获取表单并执行shell

原文:http://www.cnblogs.com/v5captain/p/6347291.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!