文章附件下载:www.pan38.com/dow/share.p… 提取密码:6664
为什么我要分享这款软件呢,因为这个工具是开源的,而且人家把源码都分享出来了,所以是开源的我们就直接把源码分享出来,学习下机器码修改的原理和一些知识,帮我底层的电脑知识,仅供学习。
源码部分:
import uuid
import platform
import subprocess
import re
import random
import ctypes
import sys
import os
from typing import Optional
class MachineCodeModifier:
def init(self):
self.system_info = {
'os': platform.system(),
'node': platform.node(),
'release': platform.release(),
'version': platform.version(),
'machine': platform.machine(),
'processor': platform.processor(),
'mac_address': self._get_mac_address(),
'disk_serial': self._get_disk_serial(),
'bios_info': self._get_bios_info()
}
def _get_mac_address(self) -> str:
"""获取当前MAC地址"""
mac = uuid.getnode()
return ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2))
def _get_disk_serial(self) -> Optional[str]:
"""尝试获取磁盘序列号"""
try:
if sys.platform == 'win32':
import wmi
c = wmi.WMI()
for disk in c.Win32_DiskDrive():
return disk.SerialNumber.strip()
elif sys.platform == 'linux':
result = subprocess.run(['hdparm', '-I', '/dev/sda'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = result.stdout.decode()
match = re.search(r'Serial\sNumber:\s(\S+)', output)
if match:
return match.group(1)
except Exception:
return None
return None
def _get_bios_info(self) -> dict:
"""获取BIOS信息"""
info = {}
try:
if sys.platform == 'win32':
import wmi
c = wmi.WMI()
for bios in c.Win32_BIOS():
info['manufacturer'] = bios.Manufacturer
info['version'] = bios.Version
info['serial'] = bios.SerialNumber
elif sys.platform == 'linux':
with open('/sys/class/dmi/id/bios_vendor', 'r') as f:
info['manufacturer'] = f.read().strip()
with open('/sys/class/dmi/id/bios_version', 'r') as f:
info['version'] = f.read().strip()
with open('/sys/class/dmi/id/bios_date', 'r') as f:
info['date'] = f.read().strip()
except Exception:
pass
return info
def generate_random_mac(self) -> str:
"""生成随机MAC地址"""
return ':'.join(['%02x' % random.randint(0, 255) for _ in range(6)])
def generate_random_serial(self, length: int = 12) -> str:
"""生成随机序列号"""
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
return ''.join(random.choice(chars) for _ in range(length))
def display_current_info(self):
"""显示当前系统信息"""
print("=== 当前系统信息 ===")
for key, value in self.system_info.items():
print(f"{key.upper()}: {value}")
print("===================")
def modify_mac_address(self, new_mac: str = None):
"""修改MAC地址(需要管理员权限)"""
if not new_mac:
new_mac = self.generate_random_mac()
print(f"尝试修改MAC地址为: {new_mac}")
if sys.platform == 'win32':
try:
# 这里只是示例,实际修改需要更复杂的操作
print("在Windows上修改MAC地址需要管理员权限和特定命令")
except Exception as e:
print(f"修改失败: {e}")
elif sys.platform == 'linux':
try:
# 同样只是示例
print("在Linux上修改MAC地址需要ifconfig或ip命令")
except Exception as e:
print(f"修改失败: {e}")
else:
print(f"不支持的操作系统: {sys.platform}")
def run(self):
"""主运行方法"""
self.display_current_info()
print("\n选项:")
print("1. 显示当前信息")
print("2. 生成随机MAC地址")
print("3. 修改MAC地址")
print("4. 退出")
while True:
choice = input("\n请输入选项(1-4): ")
if choice == '1':
self.display_current_info()
elif choice == '2':
print(f"生成的随机MAC地址: {self.generate_random_mac()}")
elif choice == '3':
self.modify_mac_address()
elif choice == '4':
print("退出程序")
break
else:
print("无效选项,请重新输入")
if name == 'main':
try:
modifier = MachineCodeModifier()
modifier.run()
except Exception as e:
print(f"程序出错: {e}")
if sys.platform == 'win32':
import ctypes
if ctypes.windll.shell32.IsUserAnAdmin() == 0:
print("提示: 某些操作可能需要管理员权限")