import wmi
def connect():
# c = wmi.WMI(computer=ipaddress,user="contoso\admin",password="Contoso#134")
c = wmi.WMI()
dev_info = {
'operation':None,
'computer':None,
'cpu':None,
'disk':None,
'mem':None,
'network':None,
'soft':None
}
#operation
operation_list = []
for operation in c.Win32_OperatingSystem():
operationinfo={'osCaption':operation.Caption,'OSArchitecture':operation.OSArchitecture ,'osVersion ':operation.Version ,'osLanguages':operation.MUILanguages}
operation_list.append(operationinfo)
dev_info['operation'] = operation_list
#disk
disk_list = []
for disk in c.Win32_LogicalDisk():
diskinfo = {'diskDescription':disk.Description,'diskDeviceID': disk.DeviceID ,'diskSize':str(disk.Size),'diskFreeSpace':str(disk.FreeSpace),'diskProviderName':disk.ProviderName}
disk_list.append(diskinfo)
dev_info['disk'] = disk_list
# soft
soft_list = []
for soft in c.Win32_Product():
if soft.Caption == None:
continue
else:
softinfo = {'softCaption':soft.Caption,'softInstallDate':soft.InstallDate}
soft_list.append(softinfo)
dev_info['soft'] = soft_list
#cpu
cpu_list = []
for cpu in c.Win32_Processor():
cpuinfo = {'cpuname':cpu.name,'cpuDataWidth':cpu.DataWidth}
cpu_list.append(cpuinfo)
dev_info['cpu'] = cpu_list
#computer
computer_list = []
for computer in c.Win32_ComputerSystem():
comptinfo = {'computerCaption':computer.Caption,'computerDomain':computer.Domain,'computerUserName':computer.UserName}
computer_list.append(comptinfo)
dev_info['computer'] = computer_list
#mem
mem_list = []
for mem in c.Win32_PhysicalMemory():
meminfo = {'memCaption':mem.Caption,'memDeviceLocator':mem.DeviceLocator,'memsize':str(int(mem.Capacity)/1048576)}
mem_list.append(meminfo)
dev_info['mem'] = mem_list
#network
network_list = []
for network in c.Win32_NetworkAdapterConfiguration (IPEnabled=1):
nicinfo = {'Caption': network.Caption, 'IP': network.IPAddress, 'MAC': network.MACAddress}
network_list.append(nicinfo)
dev_info['network'] = network_list