@echo off
(for /f "tokens=1*" %%a in (ipTable.txt) do (
ping %%a >nul && echo %%a OK||echo %%a Failed
))>result.txttoken
会读取ipTable.txt中的内容,ipTable示例:ip
testComputerName1test
testComputerName2文件
testComputerName3ping
.....bat
此外,若是ipTable.txt中有多列,列与列中间以空格分隔,则一样能够被识别,且只识别第一列,例如ab
testComputerName1 列2 列3 列4 ......
testComputerName2 列2 列3 列4 ......
testComputerName3 列2 列3 列4 ......
.....
将上述代码保存成.bat格式的文件,将存储有ip地址或者机器名的ipTable.txt放入同一目录下,执行XXX.bat便可,结果将会被保存成result.txt,result.txt示例:
testComputerName1 OK
testComputerName2 Failed
testComputerName3 OK
.....