【无标题】pyhon获取本机的ip地址和mac地址

import socket
import uuid

try:
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("8.8.8.8", 80))
    ip = s.getsockname()[0]
    mac = uuid.UUID(int=uuid.getnode()).hex[-12:]
    AC = ":".join([mac[i: i + 2] for i in range(0, 11, 2)])
finally:
    s.close()
print("ip:",ip)
print("mac:",AC)

在这里插入图片描述

你可能感兴趣的:(python,机器学习,python)