only go online if we can connect via tor

This commit is contained in:
j 2016-02-25 17:13:22 +05:30
parent d7528f634f
commit 9fd2beb147

View file

@ -386,10 +386,14 @@ def can_connect_dns(host="8.8.8.8", port=53):
host: 8.8.8.8 (google-public-dns-a.google.com) host: 8.8.8.8 (google-public-dns-a.google.com)
port: 53/tcp port: 53/tcp
""" """
import socks
import state
try: try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM, 6)
s.settimeout(1) sock.settimeout(1)
s.connect((host, port)) socks_port = state.tor.socks_port if state.tor else 9150
sock.set_proxy(socks.SOCKS5, "localhost", socks_port, True)
sock.connect((host, port))
return True return True
except: except:
pass pass