konfigurasi tor di macos

install package

brew install tor
pip install requests[socks]
pip install stem

tor config

# copy on mac /usr/local/etc/tor/torrc.sample ke torrc
# on ubuntu, file ada di /etc/tor/torrc
# uncomment
ControlPort 9051
# and
CookieAuthentication 1
# change line above to
CookieAuthentication 0

code example

# code example :: app.py
import requests
import time
proxies = {
'http': 'socks5://localhost:9050',
'https': 'socks5://localhost:9050'
}
url = 'http://httpbin.org/ip'

# refresh IP
from stem import Signal
from stem.control import Controller
# signal TOR for a new connection 
def renew_connection():
with Controller.from_port(port = 9051) as controller:
controller.authenticate()
controller.signal(Signal.NEWNYM)
for i in range(5):
print(requests.get(url, proxies=proxies).text)
renew_connection()
time.sleep(5)

jalankan

tor
python app.py

reference

http://stackoverflow.com/questions/30286293/make-requests-using-python-over-tor
https://www.wildcardcorp.com/blog/tor-torify-torsocks
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.