@echo off
(for /f "tokens=1*" %%a in (ipTable.txt) do (
ping %%a >nul && echo %%a OK||echo %%a Failed
))>result.txt
會讀取ipTable.txt中的內容,ipTable示例:
testComputerName1
testComputerName2
testComputerName3
.....
此外,如果ipTable.txt中有多列,列與列中間以空格分隔,則同樣可以被識別,且只識別第一列,例如
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
.....
