> i need to get an ip address from list of hostnames which are in a textfile.
>
> this is what i have so far
> --------------------------------------------------------------------------
> #!/usr/bin/env python
> #Get the IP Address
>
> import socket
> hostname = 'need it to read from a text file'
> addr = socket.gethostbyname(hostname)
> print 'The address of ', hostname, 'is', addr

$ cat hostnames
google.com
microsoft.com
facebook.com

$ python3
Python 3.2.3 (default, May  3 2012, 15:51:42)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> for line in open("hostnames"):
...     hostname = line.strip()
...     print("IP address for {0} is {1}.".format(hostname,
socket.gethostbyname(hostname)))
...
IP address for google.com is 74.125.225.33.
IP address for microsoft.com is 64.4.11.37.
IP address for facebook.com is 69.171.237.16.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to