[connection.py] fix local link ipv6
Signed-off-by: XiaoliChan <2209553467@qq.com>main
parent
fb2cef28da
commit
53d7d06fcf
|
@ -9,6 +9,7 @@ from os.path import isfile
|
||||||
from threading import BoundedSemaphore
|
from threading import BoundedSemaphore
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
from ipaddress import ip_address
|
||||||
|
|
||||||
from cme.config import pwned_label
|
from cme.config import pwned_label
|
||||||
from cme.helpers.logger import highlight
|
from cme.helpers.logger import highlight
|
||||||
|
@ -26,12 +27,12 @@ def gethost_addrinfo(hostname):
|
||||||
try:
|
try:
|
||||||
for res in getaddrinfo( hostname, None, AF_INET6, SOCK_DGRAM, IPPROTO_IP, AI_CANONNAME):
|
for res in getaddrinfo( hostname, None, AF_INET6, SOCK_DGRAM, IPPROTO_IP, AI_CANONNAME):
|
||||||
af, socktype, proto, canonname, sa = res
|
af, socktype, proto, canonname, sa = res
|
||||||
|
host = canonname if ip_address(sa[0]).is_link_local else sa[0]
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
for res in getaddrinfo( hostname, None, AF_INET, SOCK_DGRAM, IPPROTO_IP, AI_CANONNAME):
|
for res in getaddrinfo( hostname, None, AF_INET, SOCK_DGRAM, IPPROTO_IP, AI_CANONNAME):
|
||||||
af, socktype, proto, canonname, sa = res
|
af, socktype, proto, canonname, sa = res
|
||||||
if not sa[0]:
|
host = canonname if not sa[0] else sa[0]
|
||||||
return canonname
|
return host
|
||||||
return sa[0]
|
|
||||||
|
|
||||||
def requires_admin(func):
|
def requires_admin(func):
|
||||||
def _decorator(self, *args, **kwargs):
|
def _decorator(self, *args, **kwargs):
|
||||||
|
|
Loading…
Reference in New Issue