Cameron Simpson
2015-07-13 00:25:32 UTC
Hello,
I am working on a 2 individual programs. In the first program, I am taking in a list of domains in .csv format and want to get the associated IPs.
In the second program, I want to import in a list of IP .csv and than get the associated domains out.
Eventually I want to get both of the above programs to write out to the same .csv file that they are reading from- in the next column. But I am not there yet.
Doing research I came across the following example:http://python.about.com/od/pythonstandardlibrary/qt/dnscheck.htm
import csv
import socket
domains = open('top500domains.csv', 'r')
You're getting a whole line here, including the traling newline. Add this line:I am working on a 2 individual programs. In the first program, I am taking in a list of domains in .csv format and want to get the associated IPs.
In the second program, I want to import in a list of IP .csv and than get the associated domains out.
Eventually I want to get both of the above programs to write out to the same .csv file that they are reading from- in the next column. But I am not there yet.
Doing research I came across the following example:http://python.about.com/od/pythonstandardlibrary/qt/dnscheck.htm
import csv
import socket
domains = open('top500domains.csv', 'r')
print("domain=%r" % (domain,))
at the start of the loop to see this.
domain = socket.gethostbyname(str(domains))
There's no point converting a line to str; a line is a str. If you're wokringfrom example code I suppose you might have mistyped "strip".
Anyway, you're passing a string ending in a newline to gethostbyname. It will
not resolve.
print(domains + "\n")
For the code above, I receive the following error on run: socket.gaierror: [Errno -2] Name or service not known.
As the exception suggests. When debugging issues like these, _always_ put inFor the code above, I receive the following error on run: socket.gaierror: [Errno -2] Name or service not known.
print() calls ahead of the failing function to ensure that you are passing the
values you think you're passing.
import csv
import socketdomains = []
line = line.strip()
domains.append(line)
hostbyname_ex = socket.gethostbyname_ex(str(domains))
gethostbyname_ex takes a single hostname string. You are passing a list ofimport socketdomains = []
line = line.strip()
domains.append(line)
hostbyname_ex = socket.gethostbyname_ex(str(domains))
strings.
print(hostbyname_ex)
I receive the same error as the first variation.
Please share your advice and let me know what I am doing wrong. The top500domains.csv list is attached.
Plenty of mailing list software strips attachments. In future, unless the fileI receive the same error as the first variation.
Please share your advice and let me know what I am doing wrong. The top500domains.csv list is attached.
is large, just append the contents below your message (with some explaination).
Cheers,
Cameron Simpson <***@zip.com.au>
Life is uncertain. Eat dessert first. - Jim Blandy
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://ma