Created
October 13, 2018 18:52
-
-
Save postworthy/3fc8875cf8f6e0764ab89586b63100f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import sys | |
import bluetooth | |
import time | |
import RPi.GPIO as GPIO | |
import httplib | |
import socket | |
import socks | |
from subprocess import Popen, PIPE | |
def tor_connection(): | |
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050, True) | |
socket.socket = socks.socksocket | |
def tor_check(): | |
tor_connection() | |
con = httplib.HTTPSConnection('check.torproject.org') | |
con.request('GET', '/') | |
response = con.getresponse() | |
if "Congratulations." in response.read(): | |
print("Connected to Tor!") | |
else: | |
print("Not Connected to Tor!") | |
print("Restarting Tor...") | |
os.system("sudo service tor restart") | |
def connections_check(): | |
p = Popen(["w"], stdout=PIPE) | |
(output, error) = p.communicate() | |
exit_code = p.wait() | |
if "localhost" in output: | |
print("Someone is Connected through Tor!") | |
else: | |
print("No Connections from Tor!") | |
print("Restarting Tor...") | |
os.system("sudo service tor restart") | |
def main(): | |
while True: | |
print("Checking Tor") | |
try: | |
tor_check() | |
except Exception: | |
print("Error Checking Tor!") | |
pass | |
print("Checking Connections from Tor") | |
try: | |
connections_check() | |
except Exception: | |
print("Error Checking Connections!") | |
pass | |
print("Sleeping for 300s") | |
time.sleep(300) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment