Skip to content

Instantly share code, notes, and snippets.

@clearnote01
Created June 10, 2016 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clearnote01/94cdd302a846e81e6c9b5d53866eff4c to your computer and use it in GitHub Desktop.
Save clearnote01/94cdd302a846e81e6c9b5d53866eff4c to your computer and use it in GitHub Desktop.
#!/bin/python3
# Python 3 required !!
# do 'pip3 install pysocks' for socks module
import sys
import socket
try:
import socks
except ImportError:
print('Pysocks not installed, do "pip3 install pysocks"')
print('If pip3 is not installed do "sudo apt-get install python3-pip"')
sys.exit(1)
try:
from urllib.request import urlopen
except:
print('You are not using python3 but just python')
print('Run the script as "python3 {}"'.format(__file__))
sys.exit(2)
# Configuration
SOCKS5_PROXY_HOST = '127.0.0.1'
# Important !!
# For tor browser port is 9150, for cli of tor, it is 9050
# Set accordingly
SOCKS5_PROXY_PORT = 9150
# No need to touch
socks.setdefaultproxy(proxy_type=socks.PROXY_TYPE_SOCKS5,addr=SOCKS5_PROXY_HOST,port=SOCKS5_PROXY_PORT)
socket.socket = socks.socksocket
# function to send GET to url
# timeout may be modified suitably
def load_url(url):
try:
resp = urlopen(url,timeout=5)
print(resp.read())
resp.close()
except OSError:
print('Time out')
# Important !!
# interval of time (in seconds) to send request
# should be somewhere b/w 30-60 in final stage
interv = 30
# loop load_p with time interval interv
import time
while True:
url = 'http://icanhazip.com'
# Url below is much faster, should be used at final stage
# url = 'http://www.msftncsi.com/ncsi.txt'
load_url(url)
time.sleep(interv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment