python实现获取电脑IP、主机名、Mac地址

时间:2023-03-09 18:17:01
python实现获取电脑IP、主机名、Mac地址
import socket
import uuid # 获取主机名
hostname = socket.gethostname()
#获取IP
ip = socket.gethostbyname(hostname)
# 获取Mac地址
def get_mac_address():
mac=uuid.UUID(int = uuid.getnode()).hex[-:]
return ":".join([mac[e:e+] for e in range(,,)]) # ipList = socket.gethostbyname_ex(hostname)
# print(ipList)
print("主机名:",hostname)
print("IP:",ip)
print("Mac地址:",get_mac_address()) 原文链接:https://blog.****.net/lm_is_dc/article/details/80437053