Search code examples
pythonhttpip

Get IP address of URL in Python?


Possible Duplicate:
How can I do DNS lookups in Python, including referring to /etc/hosts?

I'm using Python 2.7 and I'm creating a iptracer with an online API.

I want the user to have the option to type e.g. google.com, http://google.com or www.google.com and then get the IP address of that and add the IP to a variable.

Is it any links or other help anyone can give me?


Solution

  • >>> import socket
    >>> print socket.gethostbyname('google.com')
    74.125.236.52