From 9fd2beb147cc8434c700734988f010ba284bc716 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 25 Feb 2016 17:13:22 +0530 Subject: [PATCH] only go online if we can connect via tor --- oml/utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/oml/utils.py b/oml/utils.py index dec05fb..c8c3084 100644 --- a/oml/utils.py +++ b/oml/utils.py @@ -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) port: 53/tcp """ + import socks + import state try: - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.settimeout(1) - s.connect((host, port)) + sock = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM, 6) + sock.settimeout(1) + 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 except: pass