当前位置:   article > 正文

Python电脑硬件信息获取_python获取电脑硬件信息

python获取电脑硬件信息

python查看电脑基本硬件信息

import psutil
import platform
import wmi

# ----------------------------------------------------------------------------------------------------------------


# import psutil

# 系统的内存利用率
free = str(round(psutil.virtual_memory().free / (1024.0 * 1024.0 * 1024.0), 2))+'GB'
total = str(round(psutil.virtual_memory().total / (1024.0 * 1024.0 * 1024.0), 2))+'GB'
memory_use_percent = str(psutil.virtual_memory().percent)+' %'
# print('可用内存:',free) # 可用内存: 8.14GB
print('总内存',total) # 总内存 15.73GB
print('内存占用率',memory_use_percent) # 内存占用率 48.2%
# cpu1秒内的占用率,和任务管理器显示的不一样,大概管理器里面的为一半
# print('cpu占用率', str(psutil.cpu_percent(interval=1))+' %') # cpu占用率 31.5%
print('物理cpu个数',psutil.cpu_count(logical=False)) # 物理cpu个数 4


# ----------------------------------------------------------------------------------------------------------------
# import platform

# print("您的系统为:" + platform.system())  # Windows
print("您的操作系统名称及版本号:" + platform.platform()) # Windows-10-10.0.19041-SP0
# print("您的操作系统版本号:" + platform.version()) # 10.0.19041
# print("您的CPU生产商为:" + platform.machine()) # AMD64
# print("您的CPU信息为:" + platform.processor()) # Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
# print("获取操作系统的位数:" ,platform.architecture()) # ('64bit', 'WindowsPE')
print("计算机的网络名称:" + platform.node()) # DESKTOP-K2Q78MR
# print("包含上面所有的信息汇总:" , platform.uname())

# ----------------------------------------------------------------------------------------------------------------
# pip install wmi
# pip install pypiwin32
# import wmi
cpuinfo = wmi.WMI()
for cpu in cpuinfo.Win32_Processor():

    # print("您的CPU序列号为:" + cpu.ProcessorId.strip()) # BFEBFBFF0999906C1
    print("您的CPU名称为:" + cpu.Name) # 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    print("您的CPU已使用:%d%%" % cpu.LoadPercentage) # 17%
    print("您的CPU核心数为:%d" % cpu.NumberOfCores) # 4
    # print("您的CPU时钟频率为:%d" % cpu.MaxClockSpeed) # 1690
# ----------------------------------------------------------------------------------------------------------------
def get_fs_info():
    """
    获取文件系统信息
    包含分区的大小、已用量、可用量、使用率、挂载点信息
    """
    tmplist = []
    c = wmi.WMI()
    for physical_disk in c.Win32_DiskDrive():
        # print(physical_disk)
        for partition in physical_disk.associators("Win32_DiskDriveToDiskPartition"):
            # print(partition)
            for logical_disk in partition.associators("Win32_LogicalDiskToPartition"):
                # print(logical_disk)
                tmpdict = {}
                tmpdict["Caption"] = logical_disk.Caption
                tmpdict["DiskTotal"] = int(logical_disk.Size) / 1024 / 1024 / 1024
                tmpdict["UseSpace"] = (int(logical_disk.Size) - int(logical_disk.FreeSpace)) / 1024 / 1024 / 1024
                tmpdict["FreeSpace"] = int(logical_disk.FreeSpace) / 1024 / 1024 / 1024
                tmpdict["Percent"] = int(
                    100.0 * (int(logical_disk.Size) - int(logical_disk.FreeSpace)) / int(logical_disk.Size))
                tmplist.append(tmpdict)
    return tmplist
# testPlatform()
# 获取磁盘信息
fs = get_fs_info()
for f in fs:
  disk_name = f['Caption']  # 磁盘名
  DiskTotal = f['DiskTotal']  # 磁盘大小 单位G
  disk_UseSpace = f['UseSpace']  # 已用磁盘大小 单位G
  disk_FreeSpace = f['FreeSpace']  # 剩余可用磁盘大小 单位G
  print('磁盘名:{}  磁盘大小:{}G   已用空间:{}G  剩余可用空间:{}G !!'.format(disk_name, round(DiskTotal, 2), round(disk_UseSpace, 2),round(disk_FreeSpace, 2)))

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/156804
推荐阅读
相关标签
  

闽ICP备14008679号