Created
August 21, 2016 07:16
-
-
Save sanderjo/dd0a55b5f87c90724afc6e8d39f91ab1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
selftesthost = "test-ipv6.sabnzbd.org" | |
#selftesthost = "test-ipv6.sabnzbd.org" | |
import socket | |
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
def test_ipv6(): | |
""" Check if external IPv6 addresses are reachable """ | |
if not selftesthost: | |
# User disabled the test, assume active IPv6 | |
return True | |
try: | |
# info = socket.getaddrinfo(cfg.selftest_host(), 443, socket.AF_INET6, socket.SOCK_STREAM, socket.IPPROTO_IP, socket.AI_CANONNAME) | |
info = socket.getaddrinfo(selftesthost, 443, socket.AF_INET6, socket.SOCK_STREAM, socket.IPPROTO_IP, socket.AI_CANONNAME) | |
except: | |
logging.debug("Test IPv6: Disabling IPv6, because it looks like it's not available. Reason: %s", sys.exc_info()[0] ) | |
return False | |
try: | |
af, socktype, proto, canonname, sa = info[0] | |
sock = socket.socket(af, socktype, proto) | |
sock.settimeout(2) # 2 second timeout | |
sock.connect(sa[0:2]) | |
sock.close() | |
logging.debug('Test IPv6: IPv6 test successful. Enabling IPv6') | |
return True | |
except socket.error: | |
logging.debug('Test IPv6: Cannot reach IPv6 test host. Disabling IPv6') | |
return False | |
except: | |
logging.debug('Test IPv6: Problem during IPv6 connect. Disabling IPv6. Reason: %s', sys.exc_info()[0]) | |
return False | |
print test_ipv6() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment