700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 一键获取电脑的系统安装时间 硬盘序列号 MAC地址 补丁安装信息

一键获取电脑的系统安装时间 硬盘序列号 MAC地址 补丁安装信息

时间:2020-06-19 17:17:46

相关推荐

一键获取电脑的系统安装时间 硬盘序列号 MAC地址 补丁安装信息

查询Windows电脑的操作系统安装时间、硬盘序列号、MAC地址、补丁安装数量、和最新补丁安装时间,都有相应的命令行查询命令。但是一个一个查询有点麻烦,用Python写了一个一键查询的方法。

可将如下代码保存为计算机自查.py,使用Python运行:

import osimport reimport timeimport winregfrom contextlib import suppresspopen = lambda cmd: os.popen(cmd).read()with suppress(Exception):key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\Windows NT\CurrentVersion')install_date = winreg.QueryValueEx(key, 'InstallDate')[0]print('操作系统安装日期为:', '%d-%d-%d' % time.localtime(install_date)[:3])with suppress(Exception):raw = popen('wmic diskdrive get serialnumber')serial_hex = raw.split()[-1].strip()serial_num = bytes.fromhex(serial_hex).decode()serial_num = re.sub(r'(.)(.)', r'\2\1', serial_num).strip()print("硬盘序列号为:", serial_num)with suppress(Exception):raw = popen('ipconfig /all')mac_address = re.findall(r'[0-9A-F-]{17}', raw)[0]print('MAC地址为:', mac_address)with suppress(Exception):raw = popen('wmic qfe list full')patch_dates = re.findall('InstalledOn=(\d+)/(\d+)/(\d+)', raw)patch_dates = [(int(y), int(m), int(d)) for m, d, y in patch_dates]print('已安装的补丁数量为:', len(patch_dates))print('最新补丁安装时间为:', '%d-%d-%d' % max(patch_dates))

运行效果如下:

操作系统安装日期为: -12-7

MAC地址为: 52-1A-C5-EA-EB-B8

硬盘序列号为: S1F0NYAF632347

已安装的补丁数量为: 13

最新补丁安装时间为: -3-2

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。