【发布时间】:2016-03-28 19:32:08
【问题描述】:
我正在尝试使用 IP 地址列表创建 nslookup。我正在 Windows 7 机器上执行nslookup。我得到的错误是,当我运行nslookup 时,我每次都将变量result 恢复为零。如何获得
Server: server.address.com
Address: 10.45.66.77
Server: server.address.com
Address: 108.36.85.35
作为我的结果而不是 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)
【问题讨论】:
标签: python command-line nslookup