I need to get requested host's ip address using urllib2 like
import urllib2
req = urllib2.Request('http://www.example.com/')
r = urllib2.urlopen(req)
Is there any issues like ip = urllib2.gethostbyname(req)?
Sultan
I need to get requested host's ip address using urllib2 like
import urllib2
req = urllib2.Request('http://www.example.com/')
r = urllib2.urlopen(req)
Is there any issues like ip = urllib2.gethostbyname(req)?
Sultan
There's a socket.gethostbyname
function which will resolve the host names if that's what you mean.
Although if you already have a connection made by urllib2
, then get the destination host via your_request.get_host()
.
You can use:
import socket
socket.gethostbyname('www.google.com')
this will return the IP address for the host. Don't pass 'http://www.google.com'. That will not work.