1.一个HTML form input和一个button提供给用户输入
2.使用flask的request获取用户输入的文件名
3.判断输入异常
4.执行shell命令touch aa.txt 并返回ls查看的结果
 
flask实现获取表单并执行shell
flask实现获取表单并执行shell
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

 

相关文章:

  • 2021-05-18
  • 2021-07-18
  • 2022-12-23
  • 2022-02-02
  • 2022-12-23
  • 2021-11-16
  • 2022-01-12
  • 2022-12-23
猜你喜欢
  • 2021-07-03
  • 2021-08-13
  • 2021-06-11
  • 2021-12-31
  • 2021-09-19
  • 2022-02-11
  • 2022-12-23
相关资源
相似解决方案