简体   繁体   English

在Windows 7 Cmd提示中获取nslookup结果

[英]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.

相关问题 Python 在 windows 提示 cmd 中无法识别 - Python not recognised in windows prompt cmd Windows 命令提示符 CMD 关闭 - Windows Command Prompt CMD Close 无法在 windows cmd 提示上安装 pybluez package - cannot install pybluez package on windows cmd prompt 我的脚本打开一个Windows cmd提示符,需要帮助粘贴到其中 - My script opens a windows cmd prompt, need help pasting into it 将 output 从集成终端 VSCode 更改为 windows cmd 提示 - changing output from integrated terminal VSCode to windows cmd prompt cx_freeze exe 文件在 anaconda 提示符下工作,但在 windows cmd 命令提示符下不起作用? - cx_freeze exe file works in anaconda prompt but not in windows cmd command prompt? 如何让 pydoc 命令在 Windows 7 cmd 中工作? - How to get pydoc command working in Windows 7 cmd? 如何在Windows 10中的命令提示符(cmd)中从带有子进程模块的python脚本编写命令 - how to write command in command prompt (cmd) in windows 10 from python script with subprocess module 如何在特定位置使用 Python 在 Windows 中启动 cmd 并设置提示 Z62848E3CE5804AA9852513A? - How do I use Python to start cmd in Windows at specific location and set prompt colors? 我正在修改代码并遇到错误。 我在 windows 中使用 cmd 提示 - I am modifying code and running into errors. I am using cmd prompt in windows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM