How to change Tor identity in Python?

前端 未结 6 2267
南旧
南旧 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条回答
  •  Happy的楠姐
    2020-11-28 20:03

    The following could work:

    for i in range(0, 10):
       #somehow change tor identity
       socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050+i)
       socket.socket = socks.socksocket
    
       print(urllib2.urlopen("http://www.ifconfig.me/ip").read())
    

    You basically set set the proxy prior to making each connection. I am asuming that you have different proxies for different IPs since you have not stated how you intend to change the IP

提交回复
热议问题