Tutorial

Using Tor as a proxy with python requests

noras noras |

Tags: #Cryptography #Encryption #Python

Installing pip

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3.6 get-pip.py

Installing requirements

pip3.6 install requests
pip3.6 install pysocks

Installing and running Tor

Download from
https://www.torproject.org

Python script

import requests

session = requests.session()
session.proxies = {}
session.proxies['http'] = 'socks5h://localhost:9150'
session.proxies['https'] = 'socks5h://localhost:9150'
payload={"payload":"value"}

heads = {}
heads['User-agent'] = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36"
heads['Content-type'] = "application/json"

url="https://www.example.com"

# json
r=session.post(url,json=payload,headers=heads)

# form data
r=session.post(url,data=payload,headers=heads)

print(r.text)

About the author

noras

"Senior Software Engineer. MSc in Computer systems and Networks with big interest in security. Loves to play with Android code and does security research for fun and profit. Speaks 4 languages and codes in much more."

Related articles

Tags: #Cryptography #Encryption #Python




Copyright © 2019 - nindoda.com