Browse Source

IPv6 support

283
Emery Hemingway 11 years ago
parent
commit
8f87f7e954
  1. 44
      lib/interface.py

44
lib/interface.py

@ -315,18 +315,25 @@ class Interface(threading.Thread):
is_new = True is_new = True
# get server certificate. # get server certificate.
# Do not use ssl.get_server_certificate because it does not work with proxy # Do not use ssl.get_server_certificate because it does not work with proxy
s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) for res in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM):
try: try:
s.connect((self.host, self.port)) s = socket.socket( res[0], socket.SOCK_STREAM )
except Exception: s.connect(res[4])
# print_error("failed to connect", self.host, self.port) except:
return s = None
continue
try:
s = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_SSLv3, cert_reqs=ssl.CERT_NONE, ca_certs=None)
except ssl.SSLError, e:
s = None
continue
break
try: if s == None:
s = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_SSLv3, cert_reqs=ssl.CERT_NONE, ca_certs=None) print_error("SSL error retrieving SSL certificate:", self.host, e)
except ssl.SSLError, e:
print_error("SSL error:", self.host, e)
return return
dercert = s.getpeercert(True) dercert = s.getpeercert(True)
s.close() s.close()
cert = ssl.DER_cert_to_PEM_cert(dercert) cert = ssl.DER_cert_to_PEM_cert(dercert)
@ -339,14 +346,19 @@ class Interface(threading.Thread):
else: else:
is_new = False is_new = False
for res in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM):
try:
s = socket.socket( res[0], socket.SOCK_STREAM )
s.settimeout(2)
s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) s.connect(res[4])
s.settimeout(2) except:
s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) s = None
continue
break
try: if s == None:
s.connect(( self.host.encode('ascii'), int(self.port)))
except Exception:
print_error("failed to connect", self.host, self.port) print_error("failed to connect", self.host, self.port)
return return

Loading…
Cancel
Save