I am working on a project using tor and python, for which I have to get the server ip of the given url using pycurl.
Currently I am using the following code for simple query and response.
def query(url):
"""
Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
"""
output = StringIO.StringIO()
curl = pycurl.Curl()
curl.setopt( pycurl.URL, url )
curl.setopt( pycurl.PROXY, '188.120.228.106' )
curl.setopt( pycurl.PROXYPORT, 1080 )
curl.setopt( pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME )
curl.setopt(pycurl.CONNECTTIMEOUT, CONNECTION_TIMEOUT)
try:
curl.perform()
return output.getvalue()
except pycurl.error as exc:
raise ValueError("Unable to reach %s (%s)" % (url, exc))
Any suggestion on how to change the code so that I can also get the server IP of the given url.
Seems like the correct flag you're looking for is CURLINFO_PRIMARY_IP
.
Try using curl.getinfo(pycurl.PRIMARY_IP)
on your pycurl.Curl()
object.