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)

相关推荐
充钱大佬4 小时前
Python测试基础教程
python·log4j·apache
mCell5 小时前
你以为短链接只是 Hash + 301/302?
后端·算法·架构
咖啡八杯5 小时前
GoF设计模式——迭代器模式
java·后端·设计模式·迭代器模式
初心丨哈士奇7 小时前
Python 四大基础容器|列表篇
python
明理的信封8 小时前
AI 基础设施的“去 Python 化“:Rust 与 C# 的两条替代路径
人工智能·python·rust
IT_陈寒9 小时前
SpringBoot自动配置不是你以为的那样的智能
前端·人工智能·后端
麻雀飞吧9 小时前
2026年AI量化开发,先跑通小流程再加复杂功能
人工智能·python
daphne odera�9 小时前
PyCharm 中 Codex 插件启动失败:unknown variant default 的解决方法
python·chatgpt·pycharm
nbu04william9 小时前
Deepseek-api省token的用法
python·大模型·token·deepseek
测试老哥10 小时前
Pytest自动化测试详解
自动化测试·软件测试·python·测试工具·测试用例·pytest·接口测试