Created
May 21, 2019 17:46
-
-
Save LuD1161/7d0cf331f5057594b164c885d944b8aa to your computer and use it in GitHub Desktop.
Sending request through socks proxy
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
""" | |
Taken from : | |
https://medium.com/@jasonrigden/using-tor-with-the-python-request-library-79015b2606cb | |
and | |
https://www.linuxuprising.com/2018/10/how-to-install-and-use-tor-as-proxy-in.html | |
script : install-tor.sh | |
sudo apt install apt-transport-https curl | |
sudo -i | |
echo "deb https://deb.torproject.org/torproject.org/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/tor.list | |
curl https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --import | |
gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | apt-key add - | |
apt update | |
exit | |
sudo apt install tor tor-geoipdb torsocks deb.torproject.org-keyring | |
pip install requests, pysocks | |
""" | |
import requests | |
session = requests.session() | |
session.proxies = {} | |
session.proxies['http'] = 'socks5h://localhost:9050' | |
session.proxies['https'] = 'socks5h://localhost:9050' | |
headers = {} | |
headers['User-agent'] = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" | |
# r = session.get(‘http://httpbin.org/ip', headers=headers) | |
# print(r.text) | |
# # Clear cookies after each request | |
# session.cookies.clear() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment