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

 1 import socket
 2 import uuid
 3 
 4 # 获取主机名
 5 hostname = socket.gethostname()
 6 #获取IP
 7 ip = socket.gethostbyname(hostname)
 8 # 获取Mac地址
 9 def get_mac_address():
10     mac=uuid.UUID(int = uuid.getnode()).hex[-12:]
11     return ":".join([mac[e:e+2] for e in range(0,11,2)])
12 
13 # ipList = socket.gethostbyname_ex(hostname)
14 # print(ipList)
15 print("主机名:",hostname)
16 print("IP:",ip)
17 print("Mac地址:",get_mac_address())
原文地址:https://www.cnblogs.com/wangjq19920210/p/9887311.html