Python - 获取本机IP地址、Mac地址
在python中获取ip地址和在php中有很大不同,在php中往往比较简单。那再python中怎么做呢?
直接看代码:
# Python - 获取本机IP地址、Mac地址 import socket,uuid 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)]) #获取本机电脑名 myname = socket.getfqdn(socket.gethostname( )) #获取本机ip myaddr = socket.gethostbyname(myname) print(myname) print(myaddr) print(get_mac_address())