批处理文件-循环ping多个ip并自动分别保存通及不t通的ip的结果

首先需要将你要ping的IP地址保存到一个ip.txt文本文件中。

ip.txt

192.168.0.1

192.168.0.2

192.168.0.3

192.168.0.4

192.168.0.5

然后:

在DOS窗口下输入如下命令即可在当前目前中创建ok.txt和no.txt两个文本文件

for /f %i in (ip.txt) do (ping %i -n 1 && echo %i>>ok.txt || echo %i >>no.txt)

如果要另存为bat文件,书写格式如下:

for /f %%i in (ip.txt) do (ping %%i -n 1 && echo %%i>>ok.txt || echo %%i >>no.txt)

另将ping到的结果只保存到一个文件的写法:

for /f %%i in (ip.txt) do (ping %%i -n 1 >>ip-info.txt)

猜你喜欢

转载自blog.csdn.net/boy_hxm/article/details/7519875