Ping is often used to detect network connectivity. This is faster and Pathping is slower. The advantage is that you can get routing information.
It is mostly used: ping 1.2.3.4 -t to test the network continuously, or: ping 1.2.3.4 -n 100 -l 4096.
If there are more addresses to ping, we can also use a loop to do it, such as:
for /L %I in (1,1,128) do ping 1.2.3.%I
With so much address information, it is necessary to save the information in a file, such as:
for /L %i in (1,1,128) do ping 1.2.3.%i | findStr "TTL" >> c:\1.txt
You can also write a DOS script to proceed, such as:
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%
=====================================
1. It is not case sensitive, but the naming convention is still very important.
2. The FindStr above is a system program, and it can also be replaced with Find. FindStr is more powerful than Find.
3. To get the screen input, you can use: set /p YourChoice=Please input your choice:
Among them, YourChoice is the variable name, and "Please enter your choice:" is the screen prompt.
To use this variable later, add% before and after the variable name, for example: %YourChoice%
4. To calculate, you can use: set /a YourVar=9+2, set /a YourVar=YourVar+2, set /a YourVar=%YourVar%+2
5、也可以使用函数,比如:
@echo off
set "YourVar=1"
echo the value before calling the function, YourVar: %YourVar%
call :YourFunction YourVar
echo the value after calling the function, YourVar: %YourVar%
goto :eof
::function body
::--- ---------------
:YourFunction-
set "%~1=2" -goto
:eof-
::----------------- -