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)

相关推荐
考虑考虑5 小时前
cmd局部设置java变量
运维·后端·自动化运维
2601_962078195 小时前
Python中calendar.weekday用法
python·编程技巧·calendar·日期处理·weekday
2601_962218615 小时前
万象生鲜系统业财一体化底层打通技术自动生成经营账单
大数据·数据库·人工智能·python·算法
2601_966949655 小时前
为什么量化策略需要大量历史股票数据?从回测可信度理解数据规模
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
2601_962885725 小时前
如何用 Python 扫描 A 股跳空缺口并统计缺口回补概率?
java·前端·python
李高钢6 小时前
Python FastAPI 框架入门:从零搭建你的第一个高性能 API 服务
数据库·python·fastapi
ocean21036 小时前
2025-2026年Python面试高频知识点洞察
开发语言·python·面试·python八股文
Warson_L7 小时前
Python的OrderedDict
python
隐擎fox7 小时前
高性能网络爬虫架构设计:基于 Python 的长连接复用与分布式会话池调度实践
分布式·python·网络协议·tcp/ip·高并发·网络爬虫、
Warson_L7 小时前
Python的TypedDict
python·langchain·llm