菜鸟IT的博客 >> Python
获取当前电脑windows系统的主机名称、局域网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[-12:]
return ":".join([mac[e:e+2] for e in range(0,11,2)])
# ipList = socket.gethostbyname_ex(hostname)
# print(ipList)
print("主机名:",hostname)
print("IP:",ip)
print("Mac地址:",get_mac_address())
菜鸟IT博客[2022.03.14-19:41] 访问:324