Skip to content

Instantly share code, notes, and snippets.

@jefftriplett
Last active August 5, 2024 15:44
Show Gist options
  • Save jefftriplett/9748036 to your computer and use it in GitHub Desktop.
Save jefftriplett/9748036 to your computer and use it in GitHub Desktop.
Python Requests + Tor (Socks5)
"""
setup:
pip install requests
pip install requests[socks]
super helpful:
- http://packetforger.wordpress.com/2013/08/27/pythons-requests-module-with-socks-support-requesocks/
- http://docs.python-requests.org/en/master/user/advanced/#proxies
"""
import requests
proxies = {
'http': 'socks5://127.0.0.1:9150',
'https': 'socks5://127.0.0.1:9150'
}
def main():
url = 'http://ifconfig.me/ip'
response = requests.get(url)
print('ip: {}'.format(response.text.strip()))
response = requests.get(url, proxies=proxies)
print('tor ip: {}'.format(response.text.strip()))
if __name__ == '__main__':
main()
@kendalvictor
Copy link

$ sudo apt-get install tor
$ sudo netstat -tlnp
and search local addres of TOR

@rootVIII
Copy link

rootVIII commented Aug 8, 2018

For what it’s worth... check out ProxyRequests.... may not be as untraceable as tor but definitely works: https://github.com/rootVIII/proxy_requests

@ice1x
Copy link

ice1x commented Dec 6, 2018

Thank you very much good man!

@MikeyPPPPPPPP
Copy link

Try port 9150 with tor browser open if that didn't work

@black15
Copy link

black15 commented Jun 19, 2020

1- Tor Should be Installed
sudo apt install tor
2- Tor Service must be opened
sudo service tor start
3- install requirements
pip install requests
pip install requests[socks]
4 - change the port in the tool from 9150 to 9050
5 - RUN :)

@cj-praveen
Copy link

its works, thank a lot...

@OkkarMin
Copy link

@dznet, @itJunky, @siddiquim-vmware add a .to so your hiddenwiki host value becomes zqktlwi4fecvo6ri.onion.to

Now, time for the red pill:

The request module is not looking up the .onion domain via the socks proxy but via standard dns. Since there is no root onion domain provided by icann or other NIC operators your lookup goes off to the root dns servers then dies.

The solution is to use the socks5h:// protocol in order to enable remote DNS resolving via the socks proxy in case the local DNS resolving process fails. Use The Source Luke.

This worked for me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment