在Windows 7中可以禁用和启用Python中的网络连接吗?我在这里看到了以前关于这个的一个问题:如何以编程方式启用/禁用网络接口?(Windows XP),但仍然找不到解决办法!请与我分享密码!马丁的回答告诉我:B‘索引名
\r\r\n0 WAN Miniport (SSTP) \r\r\n1 WAN Miniport (IKEv2) \r\r\n2 WAN Miniport (L2TP) \r\r\n3 WAN Miniport (PPTP) \r\r\n4 WAN Miniport (PPPOE) \r\r\n5 WAN Miniport (IPv6) \r\r\n6 WAN Miniport (Network Monitor) \r\r\n7 Realtek RTL8102E/RTL8103E Family PCI-E Fast Ethernet NIC (NDIS 6.20) \r\r\n8 WAN Miniport (IP) \r\r\n9 Microsoft ISATAP Adapter \r\r\n10 RAS Async Adapter \r\r\n11 Atheros AR5007 802.11b/g WiFi Adapter \r\r\n12 Teredo Tunneling Pseudo-Interface \r\r\n13 Microsoft ISATAP Adapter #2 \r\r\n\r\r\n'发布于 2014-08-28 17:36:12
采取从这里开始
您需要使用subprocess启动以下命令行实用程序:
启动提升命令提示符。
# Get NIC list and index number:
wmic nic get name, index
# Enable NIC with index number: (eg: 7)
wmic path win32_networkadapter where index=7 call enable
# Disable NIC with index number: (eg: 7)
wmic path win32_networkadapter where index=7 call disable因此,在Python中,您可以使用类似于
import subprocess
# get list of adapters and find index of adapter you want to disable.
subprocess.check_output('wmic nic get name, index')若要获取适配器列表,请在了解索引后再次对其他命令运行subprocess.check_output。还要确保您正在以特权用户的身份运行python脚本。
https://stackoverflow.com/questions/25554562
复制相似问题