Thank you for your response. I gave it another try:
As suggested, first I ran the concept just in the terminal, and it worked fine:
>>> names =['173.252.120.6', '98.139.183.24']
>>> import socket
>>> for name in names:
socket.gethostbyaddr(name)
print(name)
output:
('edge-star-shv-12-frc3.facebook.com', [], ['173.252.120.6'])
('ir2.fp.vip.bf1.yahoo.com', [], ['98.139.183.24'])
However, when I run it in a program, from a CSV file, it just outputs the
content of the CSV file without running it thought socket.gethostbyaddr():
import csv
import socket
domains = []
with open('top500ips.csv', 'r') as f:
for line in f:
line = line.strip()
domains.append(line)
for name in domains:
socket.gethostbyaddr(name)
print(name)
output:
173.252.120.6
98.139.183.24
What am I missing? Thank in advance.
Thank you.
On Saturday, July 18, 2015 7:09 PM, Danny Yoo <[email protected]> wrote:
On Jul 18, 2015 3:50 PM, "Nym City via Tutor" <[email protected]> wrote:
>
> Thank you all for your responses. I have a follow up question:
>
> So if gethostbyname_ex() takes only a single hostname string, how can I use
> it to go through a list of hostnames and get their IP resolution as an output?
>
Look into loops. If you have a function that works on a single thing, you can
use a loop to apply that function for each element in a list. Any good
tutorial should show how to do this.Let us know if you run into difficulties.
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor