文章目录
python获取本机IP地址、mac地址(物理地址)、计算机名物理地址计算机名、ip地址硬盘序列号 CPU序列号 主板序列号 bios序列号bios uuid号python获取本机IP地址、mac地址(物理地址)、计算机名
物理地址
import uuiddef get_mac_address():"""获取本机物理地址,获取本机mac地址:return:"""mac=uuid.UUID(int = uuid.getnode()).hex[-12:].upper()return "-".join([mac[e:e+2] for e in range(0,11,2)])if __name__ == '__main__':mac = get_mac_address()print('本机物理地址:',mac)
计算机名、ip地址
import socketdef get_computer_name_ip():"""python获取 电脑名、ip地址:return:"""#获取本机电脑名name = socket.getfqdn(socket.gethostname())#获取本机ipaddr = socket.gethostbyname(name)return name,addrif __name__ == '__main__':myname,myaddr = get_computer_name_ip()print('电脑名:',myname)print('ip地址:',myaddr)
硬盘序列号 CPU序列号 主板序列号 bios序列号
import wmic = wmi.WMI()# # 硬盘序列号for physical_disk in c.Win32_DiskDrive():print("硬盘序列号", physical_disk.SerialNumber)# CPU序列号for cpu in c.Win32_Processor():print("CPU序列号", cpu.ProcessorId.strip())# 主板序列号for board_id in c.Win32_BaseBoard():print("主板序列号", board_id.SerialNumber)# mac地址for mac in c.Win32_NetworkAdapter():print("mac地址", mac.MACAddress)# bios序列号for bios_id in c.Win32_BIOS():print("bios序列号", bios_id.SerialNumber.strip())
bios uuid号
#!/usr/bin/env python# -*- encoding: utf-8 -*-"""@Introduce : 获取 bios-uuid@File: bios_uuid.py@Time: -12-10 16:43@Author : xia hua dong@Tel : 173 179 76823@Email: 17317976823@@pip : pip install """import platformimport subprocessif platform.system() == 'Windows':print('Windows系统')(status, BIOS_uuid) = subprocess.getstatusoutput("wmic csproduct get UUID")BIOS_uuid = BIOS_uuid.replace("UUID", "")BIOS_uuid = BIOS_uuid.replace("\n", "")BIOS_uuid = BIOS_uuid.replace(" ", "")print("主板BIOS_uuid:", BIOS_uuid)elif platform.system() == 'Linux':print('Linux系统')(status, BIOS_uuid) = subprocess.getstatusoutput("dmidecode -s system-uuid")print("主板BIOS_uuid:", BIOS_uuid)else:print('其他系统')
python获取本机 ip地址 mac地址(物理地址) 计算机名 硬盘序列号 CPU序列号 主板序列号 bios序列号 bios uuid号