前提:将wmi和pywin32模块安装好
import wmi
class NetConfClass:
wmiserver=None
nAdpt=[]
nAdptConf=[]
nAdptSetting = []
IPADDR = []
NETMASK = []
GATEWAY = []
DNS = []
gatewayCostMetric = [1]
AllAdptIdAndName = {
}
def __init__(self):
self.wmiserver = wmi.WMI()
self.nAdpt = self.wmiserver.Win32_NetworkAdapter(AdapterType='Ethernet 802.3')
# netAdpt = wmiserver.Win32_NetworkAdapterConfiguration(IPEnabled=True)
self.nAdptConf = self.wmiserver.Win32_NetworkAdapterConfiguration(IPEnabled=True)
#self.nAdptSetting = self.wmiserver.Win32_NetworkAdapterSetting()
for item in self.nAdpt:
self.AllAdptIdAndName.update({
item