[英]Get nslookup Results in Windows 7 Cmd Prompt
I'm trying to do an nslookup
with a list of IP addresses. 我正在尝试使用IP地址列表进行nslookup
。 I'm doing the nslookup
on a Windows 7 machine. 我正在Windows 7计算机上执行nslookup
。 The error I'm getting is that when I run the nslookup
, I get the variable result
back as a zero every time. 我得到的错误是,当我运行nslookup
,每次都将变量result
返回为零。 How do I get 如何得到
Server: server.address.com
Address: 10.45.66.77
Server: server.address.com
Address: 108.36.85.35
as my result instead of 0? 作为我的结果而不是0?
#!/usr/bin/env python
#purpose of script: To conduct an nslookup on a list of IP addresses
import os, csv
#get list of IP's from file
inFile='filelocation/Book1.txt'
ipList = []
with open(inFile, 'rb') as fi:
for line in fi:
line = line.replace(',', '')#remove commas and \n from list
line = line.replace('\r', '')
line = line.replace('\n', '')
ipList.append(line)# create list of IP addresses to lookup
#output results
outFile='filelocation/outFile.txt'
fo = open(outFile, 'w')
for e in ipList:
result = str(os.system('nslookup ' + e))#send nsLookup command to cmd prompt. Result = 0 everytime
fo.write(result)
os.system
doesn't return the output of the command that you run; os.system
不返回您运行的命令的输出; it prints it instead. 它打印它。
To run a command and get its output, use os.popen(...).read()
instead: 要运行命令并获取其输出,请改用os.popen(...).read()
:
result = os.popen('nslookup ' + e).read()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.