【问题标题】:Get nslookup Results in Windows 7 Cmd Prompt在 Windows 7 Cmd 提示中获取 nslookup 结果
【发布时间】: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


    【解决方案1】:

    os.system 不返回您运行的命令的输出;它会打印它。

    要运行命令并获取其输出,请改用os.popen(...).read()

    result = os.popen('nslookup ' + e).read()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-24
      • 2019-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多