I have minimal knowledge of networking. I have discovered a paradox and need advice on how to approach the solution.
Experiment 1: A mechanize browser with a tor/polipo http proxy in a python script makes a request for a URL. The actual IP shows up in the site's log. (UNEXPECTED RESULT: I would like the tor IP to be revealed.)
Experiment 2: A mechanize browser with a tor/polipo http proxy in a python script makes a request for a URL to whatismyip. The tor proxy IP as shows up in the results. (EXPECTED)
Experiment 3: A Firefox browser using the tor proxy is pointed to whatismyip. The same IP as in experiment 2 is revealed. (EXPECTED)
Experiment 4: A Chrome browser with no proxy is pointed to whatismyip and the actual IP of the machine is shown just as in experiment 1. (EXPECTED)
Experiment 5: The HTTP proxy in the system network settings on Mac OS X is set to use the tor/polipo proxy on listening port 8123. The Chrome browser in Experiment 4 now shows the same tor IP as experiment 2 and 3. (EXPECTED)
Tor is running. Polipo is running and configured to use tor port 9050.
My python code:
import sys, time, os
from mechanize import Browser
br = Browser() # Create a browser
br.set_proxies({"http": "localhost:8123"}) #set proxy
result = br.open(URL) # Open the login page
print result.read() #print resulting output
where
URL = 'http://affinityehealth.com' | URL = 'http://whatismyip.com'
#case 1 is able to find the actual IP using the browser in mechanize but not with any other browser using the tor proxy
I am trying to make the point to the administrators of the web site that while logging IP's is useful, it does not prove the physical location of the person checking in. For weeks I have demonstrated using tor that while my physical location does not change, the physical location of the info requester appears to change in the site's logs when I check in via tor.
I would really like my tor IP to show up when I use mechanize to go to this web site in an automated fashion for testing.
I have one last experiment to try and that is setting my system wide proxy setting to tor in the network control panel. I really hate leaving this checked for routine browsing though because it is significantly slower. I only want my python script to use tor via the polipo http proxy.
New to python. New to tor. New to networking so I thank you in advance for being redundantly redundant in your simple explanations.
This works with tor and mechanize:
import socks
import socket
def create_connection(address, timeout=None, source_address=None):
sock = socks.socksocket()
sock.connect(address)
return sock
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
# patch the socket module
socket.socket = socks.socksocket
socket.create_connection = create_connection
import urllib2
print urllib2.urlopen('http://icanhazip.com').read()
import mechanize
from mechanize import Browser
br = Browser()
print br.open('http://icanhazip.com').read()