Python 获取windows硬件信息 CPU/计算机名/IP

获取windows硬件信息

# -*- coding: utf-8 -*-
# @Time    : 2022/11/8 11:22
# @Author  : lzc
# @Email   : [email protected]
# @blog    : https://www.cnblogs.com/zichliang
# @File    : getInfo.py
# @Software: PyCharm
import os
import platform
import socket
import getpass
import wmi

# 获取计算机名
hostname = socket.gethostname()  # platform.uname().node

# 获取用户名
username = getpass.getuser()

# 获取本地内网IP
ip = socket.gethostbyname(hostname)

# 获取你所使用的系统名称
system_name = platform.system()  # platform.uname().system

# 获取操作系统的位数
bit_ar = platform.architecture()

# 获取你所在文件夹
pwd = os.getcwd()


c = wmi.WMI()
# 获取的你的CPU核心数以及CPU型号
def get_cpu_info():
    CPUINFO = {}
    for cpu in c.Win32_Processor():
        # CPU ID 序列号
        # print("cpu id:", cpu.ProcessorId.strip())
        CPUINFO["CpuType"] = cpu.Name
        CPUINFO["CpuCores"] = cpu.NumberOfCores
        return CPUINFO


# 获取MAC和IP地址
def get_mac_info():
    ADDRESS = []
    for interface in c.Win32_NetworkAdapterConfiguration(IPEnabled=True):
        ADDRESS.append(interface.IPAddress)
    return get_cpu_info()

你可能感兴趣的:(python,tcp/ip,开发语言,网络协议,网络)