In a Jupyter Notebook, I have a domain list like the following
domain_list=['google.com','example.com','thisisnotaworkingdomain12344321.com']
I intend to pass this list through a loop to check and if each domain is live by running a quick NSLookup. However, when I enter the following code:
for i in range(len(domain_list)):
! nslookup domain_list[i]
I am returned the following:
Server: dsldevice6.attlocal.net
Address: redacted
*** dsldevice6.attlocal.net can't find domain_list[i]: Non-existent domain
Server: dsldevice6.attlocal.net
Address: redacted
*** dsldevice6.attlocal.net can't find domain_list[i]: Non-existent domain
Server: dsldevice6.attlocal.net
Address: redacted
*** dsldevice6.attlocal.net can't find domain_list[i]: Non-existent domain
So it is obviously doing an nslookup for "domain_list[i]", not for the ith item in the domain list. Is there a solution that anyone could provide? I cannot identify a quick workaround.
Depending on what you need to do with the output, this is the kind of thing you need:
import subprocess
for domain in domain_list:
subprocess.call( ['nslookup', domain] )
Even easier is:
import socket
for domain in domain_list:
print( socket.gethostbyname( domain ) )