1

I'm currently using tor to wrap my http requests in python, my code looks like so:

import requests
import socks
import socket

socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, '127.0.0.1', 9050, True)
socket.socket = socks.socksocket

def is_up_or_down(url):
    try:
        response = requests.get(url)
    except requests.exceptions.ConnectionError:
        return {"response_code":404, "elapsed_time":0}
    return {"response_code":response.status_code, "elapsed_time":response.elapsed.total_seconds()}

Right now I have it returning the status code of the request and the elapsed time, but is it possible to get the IP that was used to make the request?

EDIT: To be clear, I want to see which IP I'm using to make the request that way I'll know if my proxy is working or not.

Stupid.Fat.Cat
  • 10,755
  • 23
  • 83
  • 144
  • 1
    Perhaps this is helpful? http://stackoverflow.com/questions/22492484/how-do-i-get-the-ip-address-from-a-http-request-using-the-requests-library – circuitBurn Sep 23 '15 at 14:25
  • Short answer: No, that's not possible. Since you can't know which exit node will be used by Tor, the web server would need to return you the IP address of the connecting client in a header field in the HTTP response. And I don't know of any standardised response field that contains that informations. There's the recent `Forwarded` field for request headers ([RFC 7239](http://tools.ietf.org/html/rfc7239)), but nothing similar exists for responses to my knowledge. – Lukas Graf Sep 24 '15 at 00:24

1 Answers1

-3

Http header Meta has a REMOTE_ADDR field