Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get IP address of url in python? [duplicate]

Tags:

python

http

web

api

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

Im using Python 2.7 and im creating a iptracer with an online API.

And 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?

-stian

like image 512
Stian Avatar asked Dec 03 '11 19:12

Stian


2 Answers

>>> import socket
>>> print socket.gethostbyname('google.com')
74.125.236.52
like image 126
Abhijit Avatar answered Oct 17 '22 10:10

Abhijit


You can use gethostbyname_ex() function located in socket module http://docs.python.org/library/socket.html

like image 43
Vladimir Kadalashvili Avatar answered Oct 17 '22 11:10

Vladimir Kadalashvili