【发布时间】:2019-07-13 13:39:20
【问题描述】:
我想编写一个 python 程序来比较 DNS 服务器 IP 列表的 DNS 服务器速度,然后相应地更改特定 wifi 连接的 windows 设置。我在哪里可以了解如何访问 DNS 设置?我不想要解决方案,只需指出正确的方向即可。
PS:我不想使用任何额外的模块,例如dnspython,只使用默认模块。
【问题讨论】:
我想编写一个 python 程序来比较 DNS 服务器 IP 列表的 DNS 服务器速度,然后相应地更改特定 wifi 连接的 windows 设置。我在哪里可以了解如何访问 DNS 设置?我不想要解决方案,只需指出正确的方向即可。
PS:我不想使用任何额外的模块,例如dnspython,只使用默认模块。
【问题讨论】:
您可以在命令行中使用以下命令来更改您的 DNS 服务器:
C:\> netsh interface ip set dns Ethernet0 static 8.8.8.8
您应该将Ethernet0 和8.8.8.8 替换为相关值。
要在 Python 中执行此操作,只需使用 subprocess 模块:
import subprocess
subprocess.run(
["netsh", "interface", "ip", "set", "dns", "Ethernet0", "static", "8.8.8.8"])
【讨论】:
Ethernet0 是您在键入 ifconfig 时看到的网络适配器的名称。要添加第二个 DNS 服务器(例如,4.4.4.4),请使用 netsh interface ip add dns Ethernet0 4.4.4.4 index=2