–
def get_ipv6():
# 用socket获取本机 IPv6 地址
try:
# 创建一个 socket 对象
with socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) as s:
# 连接到一个公共的地址来获取本机的 IPv6 地址
s.connect(('2001:db8::1', 80))
# 获取 socket 对象的地址信息
ipv6 = s.getsockname()[0]
return ipv6
except Exception as e:
print("Failed to get IPv6 address.获取ipv6地址失败,错误信息:", e)
return None
–
发表回复