Skip to content

Instantly share code, notes, and snippets.

@0xbepresent
Created August 19, 2017 14:20
Show Gist options
  • Save 0xbepresent/b81a4ca9903bbfc7aea157b8cd55f932 to your computer and use it in GitHub Desktop.
Save 0xbepresent/b81a4ca9903bbfc7aea157b8cd55f932 to your computer and use it in GitHub Desktop.
Python Script to connect to TOR via Stem.
"""
Python script to connect to TOR via STEM. I also recommend this source https://gist.github.com/KhepryQuixote/46cf4f3b999d7f658853
"""
import socks
import requests
import socket
from stem import Signal
from stem.control import Controller
from stem.util import term
def enable_socket():
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 9050)
socket.socket = socks.socksocket
def main():
with Controller.from_port(port=9051) as controller:
controller.authenticate(password="bulapalup4")
enable_socket()
# Generamos una IP, esto lo puedes poner en un FOR cada X tiempo
controller.signal(Signal.NEWNYM)
# Requests bajo una IP hidden with TOR
print "\nNew TOR connection processed."
try:
print "Requests se van hacer con la IP {}".format((requests.get('http://icanhazip.com')).content)
except:
pass
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment