【问题标题】:How to change Windows' DNS settings using only built-in modules? [closed]如何仅使用内置模块更改 Windows 的 DNS 设置? [关闭]
【发布时间】:2019-07-13 13:39:20
【问题描述】:

我想编写一个 python 程序来比较 DNS 服务器 IP 列表的 DNS 服务器速度,然后相应地更改特定 wifi 连接的 windows 设置。我在哪里可以了解如何访问 DNS 设置?我不想要解决方案,只需指出正确的方向即可。

PS:我不想使用任何额外的模块,例如dnspython,只使用默认模块。

【问题讨论】:

    标签: python windows dns


    【解决方案1】:

    您可以在命令行中使用以下命令来更改您的 DNS 服务器:

    C:\> netsh interface ip set dns Ethernet0 static 8.8.8.8
    

    您应该将Ethernet08.8.8.8 替换为相关值。

    要在 Python 中执行此操作,只需使用 subprocess 模块:

    import subprocess
    subprocess.run(
        ["netsh", "interface", "ip", "set", "dns", "Ethernet0", "static", "8.8.8.8"])
    

    【讨论】:

    • 什么是 Ethernet0 ?我假设 8.8.8.8 是 Ip。但是在 Windows 中需要两个 IP。就像 OpenDN 一样。如何输入两个 IP?
    • Ethernet0 是您在键入 ifconfig 时看到的网络适配器的名称。要添加第二个 DNS 服务器(例如,4.4.4.4),请使用 netsh interface ip add dns Ethernet0 4.4.4.4 index=2
    猜你喜欢
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    • 2013-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多