Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reset IP? #5

Open
ghost opened this issue Dec 15, 2018 · 5 comments
Open

How to reset IP? #5

ghost opened this issue Dec 15, 2018 · 5 comments

Comments

@ghost
Copy link

ghost commented Dec 15, 2018

'tr.reset_identity' does not work. What exactly needs to be configured for it to work?

`from torrequest import TorRequest

with TorRequest(proxy_port=9050, ctrl_port=9051, password=None) as tr:
response = tr.get('http://ipecho.net/plain')
print(response.text) # not your IP address

tr.reset_identity()

response = tr.get('http://ipecho.net/plain')
print(response.text) # another IP address, not yours
input('')`

@hangyao
Copy link

hangyao commented Jan 4, 2019

I think you have to create a new TorRequest instance every time?

  1. If I don't create a new instance:
with TorRequest(password='Risk1234') as tr:

    response= requests.get('http://ipecho.net/plain')
    print ("My Original IP Address:",response.text)

    tr.reset_identity() #Reset Tor
    response= tr.get('http://ipecho.net/plain')
    print ("New Ip Address",response.text)

# with TorRequest(password='Risk1234') as tr:

    tr.reset_identity() #Reset Tor
    response= tr.get('http://ipecho.net/plain')
    print ("New Ip Address",response.text)

It gives

My Original IP Address: 174.xx.xx.xx
New Ip Address 207.244.70.XX
New Ip Address 207.244.70.XX

  1. But if I create a new TorRequest instance:
with TorRequest(password='Risk1234') as tr:

    response= requests.get('http://ipecho.net/plain')
    print ("My Original IP Address:",response.text)

    tr.reset_identity() #Reset Tor
    response= tr.get('http://ipecho.net/plain')
    print ("New Ip Address",response.text)

with TorRequest(password='Risk1234') as tr:

    tr.reset_identity() #Reset Tor
    response= tr.get('http://ipecho.net/plain')
    print ("New Ip Address",response.text)

It works properly:

My Original IP Address: 174.xx.xx.xx
New Ip Address 104.244.76.xx
New Ip Address 103.234.220.xxx

  1. If I don't reset identity but create a new instance:
with TorRequest(password='Risk1234') as tr:

    response= requests.get('http://ipecho.net/plain')
    print ("My Original IP Address:",response.text)

#     tr.reset_identity() #Reset Tor
    response= tr.get('http://ipecho.net/plain')
    print ("New Ip Address",response.text)

with TorRequest(password='Risk1234') as tr:

#     tr.reset_identity() #Reset Tor
    response= tr.get('http://ipecho.net/plain')
    print ("New Ip Address",response.text)

It doesn't reset:

My Original IP Address: 174.xx.xx.xx
New Ip Address 104.244.76.xx
New Ip Address 104.244.76.xx

@hayd
Copy link

hayd commented Mar 23, 2019

Perhaps reset_identity should be called in __enter__.

It feels like there ought to be a method that would expose this e.g. reset_ip ?

@KangboLu
Copy link

Why IP doesn't change when I request it with this site "https://ipecho.net/extra", which is just a more detailed description of your IP in the same domain?

I used the 2nd approach also.

@jcgoette
Copy link

jcgoette commented Dec 4, 2019

I am usign the following to reset IP:

    tor.close()
    tor.__init__()

@VitaliiVlo
Copy link

VitaliiVlo commented Jul 20, 2020

@erdiaker
Find a solution, guys!!!
Just need to renew session after ip renewal.

just add new function to the class to renew our session

        self.session = requests.Session()
        self.session.proxies.update({
            'http': 'socks5://localhost:%d' % self.proxy_port,
            'https': 'socks5://localhost:%d' % self.proxy_port,
        })

and you need to call this function during IP renewal in reser_identity function

        self._reset_session()
        self.reset_identity_async()
        time.sleep(self.ctrl.get_newnym_wait())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants