是否可以编写一个小脚本来发送DHCP广播请求并找到DHCP服务器地址?
我需要这个项目,但是我的研究让我相信你不能在Windows上做到这一点?我需要一个适用于OSX,Linux和Windows的小脚本 .
我想你问的是XY Problem:你想知道如何通过python在windows上找到DHCP IP地址?
对于obtaining DHCP server ip from the command line,SuperUser有一个解决方案 . 你可以用 subprocess 包装 ipconfig /all ,然后解析输出:
subprocess
ipconfig /all
import subprocess # Runs a command on the cmd line res = subprocess.check_output("ipconfig /all")
好的,我将假设你的默认网关配置为指向你的DHCP服务器 . 我找到了以下包,并能够获得我的默认网关:
#!/usr/bin/env python import netifaces gateway_info = netifaces.gateways() print(gateway_info)
我当然首先必须通过pip安装 netifaces 模块:
netifaces
$> pip install --user netifaces
代码返回以下内容:
$> ./ test3.py
{'default':{2:('192.168.0.1','en0')},2:[('192.168.0.1','en0',True)]}
我希望这有帮助 .
最好的祝福,
亚伦C.
2 回答
我想你问的是XY Problem:你想知道如何通过python在windows上找到DHCP IP地址?
对于obtaining DHCP server ip from the command line,SuperUser有一个解决方案 . 你可以用
subprocess
包装ipconfig /all
,然后解析输出:好的,我将假设你的默认网关配置为指向你的DHCP服务器 . 我找到了以下包,并能够获得我的默认网关:
我当然首先必须通过pip安装
netifaces
模块:$> pip install --user netifaces
代码返回以下内容:
$> ./ test3.py
{'default':{2:('192.168.0.1','en0')},2:[('192.168.0.1','en0',True)]}
我希望这有帮助 .
最好的祝福,
亚伦C.