常常用Ping來檢測網絡的通斷,這個快一些,用Pathping慢一些,好處是能夠獲得路由信息。網絡
用的可能是:ping 1.2.3.4 -t,連續測試網絡,也能夠:ping 1.2.3.4 -n 100 -l 4096。ide
若是要Ping的地址多了,咱們也能夠用一個循環來進行,好比:函數
for /L %I in (1,1,128) do ping 1.2.3.%I測試
這麼多地址信息,須要將這些信息保存到一個文件裏,好比:code
for /L %i in (1,1,128) do ping 1.2.3.%i | findStr "TTL" >> c:\1.txt路由
也能夠寫一個DOS腳原本進行,好比:it
echo off
::設置參數
set FilePath=d:\PingResult.txt
mode con:cols=120 lines=50
set StartIP=1
set EndIP=128
set PingIP=%StartIP%
echo %date% %time% 開始掃描......>>%FilePath%
:StartPing
echo ----------1.2.3.%PingIP%---------->> %FilePath%
ping 1.2.3.%PingIP% | findStr "TTL" >> %FilePath%
echo ->> %FilePath%
set /a PingIP = %PingIP% + 1
if %PingIP% geq %EndIP% goto :EndPing
goto :StartPing
:EndPing
echo %date% %time% 結束掃描!>>%FilePath%io
=====================================class
一、不區分大小寫,可是命名習慣仍是挺重要。變量
二、上面的FindStr是一個系統程序,也能夠換成Find,FindStr比Find功能更強大。
三、獲取屏幕輸入,能夠用:set /p YourChoice=請輸入你的選擇:
其中,YourChoice是變量名,「請輸入你的選擇:」是屏幕提示。
後面要使用這個變量,變量名的先後加%,好比:%YourChoice%
四、要運算,能夠用:set /a YourVar=9+2,set /a YourVar=YourVar+2,set /a YourVar=%YourVar%+2
五、也可使用函數,好比:
@echo off set "YourVar=1" echo 沒有調用函數以前的值,YourVar: %YourVar% call :YourFunction YourVar echo 調用函數以後的值,YourVar: %YourVar% goto :eof ::函數主體 ::------------------ :YourFunction - set "%~1=2" - goto :eof - ::------------------