【问题标题】:How to Change DNS Servers Programmatically in Windows?如何在 Windows 中以编程方式更改 DNS 服务器?
【发布时间】:2011-11-16 23:07:20
【问题描述】:

我想以编程方式更改 DNS 服务器。我不想建DNS服务器,我只想自动更改主从DNS服务器。这项工作需要在 Python 中完成。

【问题讨论】:

    标签: python windows dns


    【解决方案1】:

    您可以使用 os.system 调用命令行工具为您执行此操作。

    import os
    os.system('netsh interface ip set dns "Local Area Connection" static 192.168.0.200')
    

    【讨论】:

      【解决方案2】:
      import os
      # The first thing you need to import os and identify is the name of the network interface you want to modify.
      # You can find the names of all network interfaces by running the following command:
      os.system('netsh interface ipv4 show interfaces')
      # for me its "Wi-Fi"
      # For the primary DNS server run:
      os.system('netsh interface ip set dns name="Wi-Fi" static 185.37.37.37')
      # For the secondary DNS server run:
      os.system('netsh interface ip add dns name="Wi-Fi"  185.37.39.39 index=2')
      # whene you'r done with the DNS server run :
      os.system('netsh interface ip set dnsservers name="Wi-Fi" source=dhcp')
      #keep in mind  that you need administrator privilege
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-24
        • 1970-01-01
        • 1970-01-01
        • 2012-02-02
        相关资源
        最近更新 更多