Skip to content

Instantly share code, notes, and snippets.

@mIcHyAmRaNe
Created September 12, 2017 21:50
Show Gist options
  • Save mIcHyAmRaNe/302717baeaa5d7bd34ad3f8dbae9b52d to your computer and use it in GitHub Desktop.
Save mIcHyAmRaNe/302717baeaa5d7bd34ad3f8dbae9b52d to your computer and use it in GitHub Desktop.
Python3: tor ask_yes_no
#!/usr/bin/env python3
#simple script showing how to let Python ask you if you want to use or not tor ^^
import requests
proxies = {
'http': 'socks5://127.0.0.1:9050', #make sure configuring the right port (9150 if using tor browser)
'https': 'socks5://127.0.0.1:9050'
}
def ask_yes_no(prompt):
while True:
answer = input(prompt + ' (y or n) ')
if answer == 'y' or answer == 'Y':
return True # returning ends the function
if answer == 'n' or answer == 'N':
return False
print("Answer 'y' or 'n'.")
if ask_yes_no("would you like to use tor?"):
proxies=proxies
else:
proxies=""
print(requests.get("http://ip.42.pl/raw", proxies=proxies).text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment