用Ping检测网络IP

  经常用Ping来检测网络的通断,这个快一些,用Pathping慢一些,好处是可以得到路由信息。

  用的多是:ping 1.2.3.4 -t,连续测试网络,也可以:ping 1.2.3.4 -n 100 -l 4096。

  如果要Ping的地址多了,我们也可以用一个循环来进行,比如:

  for /L %I in (1,1,128) do ping 1.2.3.%I

  这么多地址信息,需要将这些信息保存到一个文件里,比如:

  for /L %i in (1,1,128) do ping 1.2.3.%i | findStr "TTL" >> c:\1.txt

  也可以写一个DOS脚本来进行,比如:

  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、不区分大小写,但是命名习惯还是挺重要。

  2、上面的FindStr是一个系统程序,也可以换成Find,FindStr比Find功能更强大。

  3、获取屏幕输入,可以用:set /p YourChoice=请输入你的选择:

    其中,YourChoice是变量名,“请输入你的选择:”是屏幕提示。

    后面要使用这个变量,变量名的前后加%,比如:%YourChoice%

  4、要运算,可以用:set /a YourVar=9+2,set /a YourVar=YourVar+2,set /a YourVar=%YourVar%+2

  5、也可以使用函数,比如:

    @echo off
    set "YourVar=1"
    echo 没有调用函数之前的值,YourVar: %YourVar%
    call :YourFunction YourVar
    echo 调用函数之后的值,YourVar: %YourVar%
    goto :eof
    ::函数主体
    ::------------------
    :YourFunction      -
    set "%~1=2"        -
    goto :eof          -
    ::------------------

猜你喜欢

转载自blog.51cto.com/dawn0919/2583196