Browse Source

IPv6 support

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

34
lib/interface.py

@ -315,18 +315,25 @@ class Interface(threading.Thread):
is_new = True
# get server certificate.
# 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:
s.connect((self.host, self.port))
except Exception:
# print_error("failed to connect", self.host, self.port)
return
s = socket.socket( res[0], socket.SOCK_STREAM )
s.connect(res[4])
except:
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:
print_error("SSL error:", self.host, e)
s = None
continue
break
if s == None:
print_error("SSL error retrieving SSL certificate:", self.host, e)
return
dercert = s.getpeercert(True)
s.close()
cert = ssl.DER_cert_to_PEM_cert(dercert)
@ -339,14 +346,19 @@ class Interface(threading.Thread):
else:
is_new = False
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:
s = socket.socket( res[0], socket.SOCK_STREAM )
s.settimeout(2)
s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
try:
s.connect(( self.host.encode('ascii'), int(self.port)))
except Exception:
s.connect(res[4])
except:
s = None
continue
break
if s == None:
print_error("failed to connect", self.host, self.port)
return

Loading…
Cancel
Save