Created
April 30, 2021 20:43
-
-
Save sesseor/080ace057095c63b50b319fbb8caf9d7 to your computer and use it in GitHub Desktop.
Python requests over Tor (Socks5)
This file contains hidden or 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
#install `tor` | |
#sudo apt install tor | |
#sudo service tor start | |
#install `requests` | |
#pip3 install requests | |
#pip3 install requests[socks] | |
import requests | |
proxies = { | |
'http': 'socks5://127.0.0.1:9050', | |
'https': 'socks5://127.0.0.1:9050' | |
} | |
def get_ip(): | |
url = 'http://ifconfig.me/ip' | |
response = requests.get(url).text | |
print(f'host ip: {response}') | |
response = requests.get(url, proxies=proxies).text | |
print(f'tor ip: {response}') | |
if __name__ == '__main__': | |
get_ip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment