【无标题】

# -*- coding: utf-8 -*-
import wmi
import socket
import os
def sys_version():
    c = wmi.WMI()

    # 操作系统版本,版bai本号,32位/64位
    print('#########本机电脑基本信息##########')
    sys = c.Win32_OperatingSystem()[0]
    name = socket.gethostname()
    print("本机用户:",name)
    print("操作系统版本:", sys.Caption, "\n", "电脑版本号:", sys.BuildNumber, "\n","32位/64位:", sys.OSArchitecture)
    for interface in c.Win32_NetworkAdapterConfiguration(IPEnabled=1):
        print("MAC: %s" % interface.MACAddress)
    for ip_address in interface.IPAddress:
        print("电脑IP: %s" % ip_address)
        bios = c.Win32_BIOS()[0]
    for bios_id in c.Win32_BIOS():
        print('BIOS版本', bios_id.Version)
        print('Bios序列号',bios_id.SerialNumber.strip)
        print('生产厂家',bios.Manufacturer)
        print('释放日期',bios.ReleaseDate)
    for board_id in c.Win32_BaseBoard():
        print('主板序列号',board_id.SerialNumber)

    print('\nCPU信息')
    processor = c.Win32_Processor()[0]
    print('处理器:',processor.Name.strip())
    for cpu in c.Win32_Processor():
        print('CPU序列号:',cpu.ProcessorId.strip())
    Memory = c.Win32_PhysicalMemory()[0]
    print('已安装内存(RAM):', int(Memory.Capacity) // 1048576, )##'M','总内存(RAM):', int((Memory)) // 1048576, 'M'

    # 硬盘名称,硬盘剩余空间,硬盘总大小
    print('\n硬盘使用情况:')
    disk_sn_list = []
    for physical_disk in c.Win32_DiskDrive():
    # print(physical_disk.SerialNumber)
        print('硬盘序列号',physical_disk.SerialNumber.replace(" ", ""))
    for disk in c.Win32_LogicalDisk(DriveType=3):
        print(disk.Caption, '磁盘剩余量:', int(disk.FreeSpace) // 1048576, 'M\t', '磁盘总量:', int(disk.Size) // 1048576, 'M')



sys_version()
os.system('pause')
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)))

pip install xlutils
import xlrd
import xlwt
from xlutils.copy import copy
import wmi
import os

w = wmi.WMI()
global list
list = []


def info():
    # list.append("电脑信息")
    for address in w.Win32_NetworkAdapterConfiguration(ServiceName="e1dexpress"):
        list.append("%s" % address.IPAddress[0])
        list.append("%s" % address.MACAddress)
    for BIOS in w.Win32_BIOS():
        list.append("%s" % BIOS.SerialNumber)
    for processor in w.Win32_Processor():
        list.append("%s" % processor.Name.strip())
    for memModule in w.Win32_PhysicalMemory():
        totalMemSize = int(memModule.Capacity)
        list.append("%.2fGB" % (totalMemSize / 1024 ** 3))
    for xk in w.Win32_VideoController():
        list.append("%s" % xk.name)


def write_excel_xls(path, sheet_name, value):
    index = len(value)  # 获取需要写入数据的行数
    workbook = xlwt.Workbook()  # 新建一个工作簿
    sheet = workbook.add_sheet(sheet_name)  # 在工作簿中新建一个表格
    for i in range(0, index):
        for j in range(0, len(value[i])):
            sheet.write(i, j, value[i][j])  # 像表格中写入数据(对应的行和列)
    workbook.save(path)  # 保存工作簿
    print("xls格式表格写入数据成功!")


def write_excel_xls_append(path, value):
    index = len(value)  # 获取需要写入数据的行数
    workbook = xlrd.open_workbook(path)  # 打开工作簿
    sheets = workbook.sheet_names()  # 获取工作簿中的所有表格
    worksheet = workbook.sheet_by_name(sheets[0])  # 获取工作簿中所有表格中的的第一个表格
    rows_old = worksheet.nrows  # 获取表格中已存在的数据的行数
    new_workbook = copy(workbook)  # 将xlrd对象拷贝转化为xlwt对象
    new_worksheet = new_workbook.get_sheet(0)  # 获取转化后工作簿中的第一个表格
    for i in range(0, index):
        for j in range(0, len(value[i])):
            new_worksheet.write(i + rows_old, j, value[i][j])  # 追加写入数据,注意是从i+rows_old行开始写入
    new_workbook.save(path)  # 保存工作簿
    print("xls格式表格【追加】写入数据成功!")


def read_excel_xls(path):
    workbook = xlrd.open_workbook(path)  # 打开工作簿
    sheets = workbook.sheet_names()  # 获取工作簿中的所有表格
    worksheet = workbook.sheet_by_name(sheets[0])  # 获取工作簿中所有表格中的的第一个表格
    for i in range(0, worksheet.nrows):
        for j in range(0, worksheet.ncols):
            print(worksheet.cell_value(i, j), "\t", end="")  # 逐行逐列读取数据
        print()


info()

book_name_xls = '计算机硬件信息.xls'

sheet_name_xls = '计算机硬件信息表'

value_title = [["IP地址", "MAC地址", "主板型号", "CPU型号", "内存大小", "显卡名称"], ]

value1 = [[list[0], list[1], list[2], list[3], list[4], list[5]], ]

write_excel_xls(book_name_xls, sheet_name_xls, value_title)
write_excel_xls_append(book_name_xls, value1)
# write_excel_xls_append(book_name_xls, value2)
# read_excel_xls(book_name_xls)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

贾激光

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值