2017-10-28 87 views
-2

我想通过获取URL运行域名的列表,以获取IP地址

for url in list: 

Host = "host %s" % url 

IPADDRESS = subprocess.check_output(HOST, shell=True) 

print IPADDRESS 
+0

新的编程..有一个域名列表,我想运行主机命令并将结果保存在IPADDRESS中 –

+0

[我如何在Python中执行DNS查找,包括引用/ etc/hosts?](https:// stackoverflow.com/questions/2805231/how-can-i-do-dns-lookups-in-p ython-including-references-to-etc-hosts) – Evan

+0

什么是'IPADDRESS = subprocess.check_output(['host',url])'为你做? –

回答

0

的URL列表中运行 “主机domain.com”:

os.system("host %s | grep 'has address' | sort -u" % (url)) 
+0

想要使用subprocess.check_output,但至少它是弹出一些结果..仍然grep命令不工作。 –

0
enter code here 
#!/usr/bin/python 
import subprocess 
list = ("/root/cisco/indexlist.txt","r") 
for hostname in list: 
p1 = subprocess.Popen(['host', hostname],stdout=subprocess.PIPE) 
p2 = subprocess.Popen(['grep', 'IP ADDRESS'], stdin=p1.stdout, stdout=subprocess.PIPE) 
p3 = subprocess.Popen(['sort','-u'],stdin=p2.stdout, stdout=subprocess.PIPE) 
print (p3.communicate()[0]) 
+0

**认为它会有用一些**检查和它的工作 –