zoukankan      html  css  js  c++  java
  • Python 获取本地主机信息

    import wmi
    
    c = wmi.WMI()
    
    for sys in c.Win32_OperatingSystem():
        #系统信息
        print(sys.Caption)
        #系统版本号
        print(sys.BuildNumber)
        #32/64位
        print(sys.OSArchitecture)
        #当前系统进程数
        print(sys.NumberOfProcesses)
    
    #处理器信息
    for pro in c.win32_Processor():
        print(pro.DeviceID)
        print(pro.Name.strip())
    
    #内存信息
    for Memory in c.Win32_PhysicalMemory():
        print((int(Memory.Capacity)/1048576))
    
    # 获取硬盘分区
    for physical_disk in c.Win32_DiskDrive():
        for partition in physical_disk.associators("Win32_DiskDriveToDiskPartition"):
            for logical_disk in partition.associators("Win32_LogicalDiskToPartition"):
                print(physical_disk.Caption, partition.Caption, logical_disk.Caption)
    # 获取硬盘使用百分情况
    for disk in c.Win32_LogicalDisk(DriveType=3):
        print(disk.Caption, "%0.2f%% free" % (100.0 * int(disk.FreeSpace) / int(disk.Size)))
    
    for interface in c.Win32_NetworkAdapterConfiguration(IPEnabled=1):
        print("MAC: %s" % interface.MACAddress)
    for ip_address in interface.IPAddress:
        print("ip_add: %s" % ip_address)
    # 获取自启动程序的位置
    for s in c.Win32_StartupCommand():
        print("[%s] %s <%s>" % (s.Location, s.Caption, s.Command))
    
    # 获取当前运行的进程
    for process in c.Win32_Process():
        print((process.ProcessId, process.Name))
  • 相关阅读:
    python入门第十七天_生成器 迭代器
    python入门第十六天__列表生成式
    装饰器补充知识点_ @functools.wraps(func)
    函数练习题2
    函数编程练习题1
    迭代器
    生成器的send方法
    函数写生成器
    斐波那契数列
    生成器
  • 原文地址:https://www.cnblogs.com/yincq/p/11732906.html
Copyright © 2011-2022 走看看