我想通過獲取URL運行域名的列表,以獲取IP地址
for url in list:
Host = "host %s" % url
IPADDRESS = subprocess.check_output(HOST, shell=True)
print IPADDRESS
我想通過獲取URL運行域名的列表,以獲取IP地址
for url in list:
Host = "host %s" % url
IPADDRESS = subprocess.check_output(HOST, shell=True)
print IPADDRESS
的URL列表中運行 「主機domain.com」:
os.system("host %s | grep 'has address' | sort -u" % (url))
想要使用subprocess.check_output,但至少它是彈出一些結果..仍然grep命令不工作。 –
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])
**認爲它會有用一些**檢查和它的工作 –
新的編程..有一個域名列表,我想運行主機命令並將結果保存在IPADDRESS中 –
[我如何在Python中執行DNS查找,包括引用/ etc/hosts?](https:// stackoverflow.com/questions/2805231/how-can-i-do-dns-lookups-in-p ython-including-references-to-etc-hosts) – Evan
什麼是'IPADDRESS = subprocess.check_output(['host',url])'爲你做? –