@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
.....