【问题标题】:How to find out Windows network interface name in Python?如何在 Python 中找出 Windows 网络接口名称?
【发布时间】:2018-09-12 10:48:01
【问题描述】:

Windows 命令netsh interface show interface 显示所有网络连接及其名称。名称可以是 Wireless Network ConnectionLocal Area NetworkEthernet 等。

我想用 Python 脚本用netsh interface ip set address "Wireless Network Connection" static 192.168.1.3 255.255.255.0 192.168.1.1 1 更改 IP 地址,但我需要一个网络接口名称。

是否可以像我们可以拥有带有socket.gethostname() 的主机名一样拥有这些信息?或者我可以通过其他方式使用 Python 更改 IP 地址?

【问题讨论】:

  • @RehanAzher 不,不幸的是,这并没有提供“无线网络连接”作为信息。

标签: python static-ip-address


【解决方案1】:

我不知道 Python netsh API。但是使用一对subprocess 调用应该不难。首先发出netsh interface show interface,解析返回的输出,然后发出set address 命令。

还是我没抓住重点?

【讨论】:

  • 这是我的第一个想法,但我认为也许有更简单的方法,比如 IP 地址ip = socket.gethostbyname(socket.gethostname())
猜你喜欢
  • 2012-09-10
  • 2011-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多