How to change Tor identity in Python?

前端 未结 6 2272
南旧
南旧 2020-11-28 19:14

I have the following script:

import socks
import socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, \"127.0.0.1\", 9050)
socket.socket = socks.socksocket
         


        
6条回答
  •  情话喂你
    2020-11-28 19:42

    Tor wrote a new TOR control library in Python, stem. It can be found on PyPI. They provide some nice tutorials how to work with it, one of them explains how to change your identity:

    from stem import Signal
    from stem.control import Controller
    
    with Controller.from_port(port = 9051) as controller:
      controller.authenticate()
      controller.signal(Signal.NEWNYM)
    

    Make sure your config is correct.

提交回复
热议问题