一个用于 Windows 局域网设备的 IP 上报 Demo
main.py
:API 接口,用于获取/更新局域网设备 IPcorn.py
:定时向 API 接口上报设备 IP
安装依赖
conda create lanip python=3.10
conda activate lanip
pip install flask pyinstaller
corn.py
通过 pyinstaller 打包为 exe 文件,然后注入为 Windows 系统服务:
pyinstaller -F .\corn.py -i .\nana.ico -n printer_ip_report
参数 | 含义 |
---|---|
-F | 打包文件 |
-i | 图标(可选) |
-n | 生成可执行文件名 |
注入系统服务可使用图形化界面 nssm 或者powershell的 New-Service cmdlet
启动后端接口(以 Linux 为例)
# main.py
nohup python main.py &
启动上报 IP 服务(Windows PowerShell)
.\your_exe
# 查看启动参数
.\your_exe --help