Windows server flask

1、Windows server 通过python的flask执行命令

from flask import Flask, request, abort
import subprocess
from flask_basicauth import BasicAuth

app = Flask(__name__)

# 获取url是进行账号密码认证,设置url的账号密码
app.config['BASIC_AUTH_USERNAME'] = '账号自设定'
app.config['BASIC_AUTH_PASSWORD'] = '密码自设定'

app.config['BASIC_AUTH_FORCE'] = True # 整个站点都验证

# BasicAuth初始化
basic_auth = BasicAuth(app)

# 允许访问的IP地址列表
allowed_ips = ['10.1.1.2', '10.1.1.1', '127.0.0.1', 'localhost']

# 使用 before_request 钩子进行 IP 地址检查
@app.before_request
def limit_remote_addr():
if request.remote_addr not in allowed_ips:
abort(403)

@app.route('/dhcp/showall', methods=['GET'])
def showall():
return subprocess.check_output('netsh dhcp server show all ', shell=True, text=True)

@app.route('/ipconfig', methods=['GET'])
def ipconfig():
return subprocess.check_output('ipconfig', shell=True, text=True)

# 设置 host 为 0.0.0.0,以便监听所有网络接口
app.run(host='0.0.0.0', port=8080, debug=True)

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2023-12-12 14:12:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-12 14:12:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-12 14:12:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-12 14:12:03       18 阅读

热门阅读

  1. 2024年软考高项还是机考吗?附常见问题答疑

    2023-12-12 14:12:03       33 阅读
  2. 816 - Abbott‘s Revenge (UVA)

    2023-12-12 14:12:03       42 阅读
  3. Docker入门概念

    2023-12-12 14:12:03       41 阅读
  4. 简单的小题集(八)

    2023-12-12 14:12:03       35 阅读