I am currently looking to compare my regular public IP address to a TOR IP address that I also connect to the internet with. My code is as below:-
def public_ip():
url = 'http://ifconfig.me/ip'
request = urllib2.Request(url)
request.add_header('Cache-Control','max-age=0')
response = urllib2.urlopen(request)
print response.read()
def connect_tor():
LOCALHOST = "127.0.0.1"
PORT = 9150
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, LOCALHOST, PORT)
socket.socket = socks.socksocket
url = 'http://ifconfig.me/ip'
request = urllib2.Request(url)
request.add_header('Cache-Control','max-age=0')
response = urllib2.urlopen(request)
print response.read()
if __name__ == "__main__":
public_ip()
connect_tor()
What I'm looking to do is then create a third function that will confirm the value of the IP address generated by both functions so as to confirm they are different. Nonetheless, how can I feed the IP addresses from the first two functions into a third function. Here's what I was thinking so far but I'm unsure of best option:-
1.) Just create one large function for all three functions 2.) Create global variables and return the values to the global variables and use these in the third function 3.) Call the 'connect_tor' function from within the 'public_ip' function passing the 'public_ip' to the 'connect_tor function' for the this to then call the third function by passing the two IPs as parameters.
What would be best practice here or recommendations?
I would add a return value to your current functions public_ip()
and connect_tor()
. Then simply compare them:
print public_ip() != connect_tor()
This way you can check for anonymity while avoiding another function altogether.