import socket
import socks
import urllib2
ipcheck_url = 'http://checkip.amazonaws.com/'
# Actual IP.
print(urllib2.urlopen(ipcheck_url).read())
# Tor IP.
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9050)
socket.socket = socks.socksocket
print(urllib2.urlopen(ipcheck_url).read())
This actually works fine for me. But how do I come out of "setdefaultproxy" back to Actual IP. Because I still stuck in Tor IP I'm not able to get back to Actual IP. Some where I need to close the socket. How do I do that ?
This is with reference to : How to make urllib2 requests through Tor in Python?
You can set it back to the way is was like this:
socks.setdefaultproxy(None)
socket.socket = socks.socksocket