zoukankan      html  css  js  c++  java
  • wmi获取计算机信息

    import wmi

    def connect():
    # c = wmi.WMI(computer=ipaddress,user="contosoadmin",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



  • 相关阅读:
    Run command in YMAL build pipeline or Release Pipeline
    Create Pipeline for Azure Apps
    Deploy Azure App Service with VS Code
    多线程总结笔记
    @Param注解
    Mac Idea2018.1破解
    空指针异常Caused by: java.lang.NullPointerException: null
    java集合面试题
    在IntelliJ IDEA中使用git
    分支管理
  • 原文地址:https://www.cnblogs.com/lijifei/p/14023389.html
Copyright © 2011-2022 走看看