Batch file-ping multiple ips in a loop and automatically save the results of the ips that pass and fail

First, you need to save the IP address you want to ping into an ip.txt text file.

ip.txt

192.168.0.1

192.168.0.2

192.168.0.3

192.168.0.4

192.168.0.5

 

then:

Enter the following command in the DOS window to create two text files ok.txt and no.txt in the current current

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

 

If you want to save as a bat file, the writing format is as follows:

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

 

Another way to save the ping result to a file:

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

 

 

Guess you like

Origin blog.csdn.net/boy_hxm/article/details/7519875