only go online if we can connect via tor
This commit is contained in:
parent
d7528f634f
commit
9fd2beb147
1 changed files with 7 additions and 3 deletions
10
oml/utils.py
10
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
|
||||
|
|
Loading…
Reference in a new issue