Python - Controlling Tor

前端 未结 3 717
礼貌的吻别
礼貌的吻别 2020-12-29 12:41

I\'m attempting to control Tor with Python. I\'ve read a couple of the other questions asked about this subject on stackoverflow but none of them answer this question.

3条回答
  •  佛祖请我去吃肉
    2020-12-29 12:56

    You can use a similar code in python:

    def renewTorIdentity(self, passAuth):
        try:
            s = socket.socket()
            s.connect(('localhost', 9051))
            s.send('AUTHENTICATE "{0}"\r\n'.format(passAuth))
            resp = s.recv(1024)
    
            if resp.startswith('250'):
                s.send("signal NEWNYM\r\n")
                resp = s.recv(1024)
    
                if resp.startswith('250'):
                    print "Identity renewed"
                else:
                    print "response 2:", resp
    
            else:
                print "response 1:", resp
    
        except Exception as e:
            print "Can't renew identity: ", e 
    

    You can check this post for a mini-tutorial

提交回复
热议问题