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)

相关推荐
MC丶科11 小时前
【SpringBoot常见报错与解决方案】中文乱码?Spring Boot 统一解决前后端中文乱码问题(含 Postman 测试)!别再百度“加 UTF-8”了!
spring boot·后端·postman
程序员:钧念12 小时前
深度学习与强化学习的区别
人工智能·python·深度学习·算法·transformer·rag
数据与后端架构提升之路13 小时前
TeleTron 源码揭秘:如何用适配器模式“无缝魔改” Megatron-Core?
人工智能·python·适配器模式
hele_two14 小时前
快速幂算法
c++·python·算法
l1t14 小时前
利用DeepSeek将python DLX求解数独程序格式化并改成3.x版本
开发语言·python·算法·数独
XXOOXRT15 小时前
基于SpringBoot的加法计算器
java·spring boot·后端·html5
moxiaoran575316 小时前
Go语言的错误处理
开发语言·后端·golang
Cemtery11616 小时前
Day26 常见的降维算法
人工智能·python·算法·机器学习
星空椰17 小时前
快速掌握FastAPI:高效构建Web API
python·fastapi