首页 > 解决方案 > 我怎样才能“标记”一台计算机,以便以后在 Python 上识别它?

问题描述

我正在寻找一种在 Python 中“标记”计算机的方法,以便稍后为程序提供识别计算机的选项。

如您所知,我需要计算机中独一无二的东西,或者制作无法真正操纵的复杂东西。

为了更好地理解:

我实际上是在尝试防止在另一台计算机上使用具有相同数据的程序(我将在其中放置有关计算机的独特事物或信息)。

标签: pythondetect

解决方案


它将为此使用 MAC 地址或主板 UUID。但是,MAC 地址不是每台计算机唯一的,而是每个网络接口唯一的。例如,当您更换网卡时,MAC 地址会发生变化。更多在 Python 中获取 MAC 地址的方法可以在这里找到。

from getmac import get_mac_address as gma

print(gma())

另一种看待这个的方式是;是什么让计算机与众不同?是网络设备、主板还是硬盘?或者也许是所有的组合?获取主板序列号的示例:

import os
import sys

os_type = sys.platform.lower()

if os_type.startswith('win'):
    command = "wmic bios get serialnumber"
elif "linux" in os_type:
    command = "hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.uuid"
elif "darwin" in os_type:
    command = "ioreg -l | grep IOPlatformSerialNumber"

print(os.popen(command).read())

推荐阅读