首页 运维 网络学院 查看内容

批量Ping一段IP地址

2011-9-20 22:17 1108 0

摘要:   花了两个小时写了一个简单的Batch文件, 主要作用是Ping一段指定的IP并将结果保存到一个文本文件, 不要笑我, 水平有点差。 写的时候参考了这篇文章http://batcracker.blo...
关键词: nbsp echo startHostAdd logfile networkAdd Ping set goto counter startIP

  花了两个小时写了一个简单的Batch文件, 主要作用是Ping一段指定的IP并将结果保存到一个文本文件, 不要笑我, 水平有点差。 写的时候参考了这篇文章http://batcracker.blog.51cto.com/3576884/667421的内容, 功能还不完善, 没有什么防错措施, 还有只能使用同一网段的C类地址ping, 陆续会改进:  @echo off  echo *******************************************************************************  echo * This Batch is used to automatically ping a series of continuous IP and save *  echo * the result to a file.                                                       *  echo *                                                                             *  echo * Version: 1.0                                                                *  echo * Author:  Tom Xue                                                            *  echo * Email:   [email protected]                                                  *  echo * Update:  09/18/2011                                                         *  echo *******************************************************************************  echo.  color 79  echo Please input a start IP:  set /p startIP=  echo Please input a End IP:  set /p endIP=  echo Please input the full path of the Log file (D:\ping.txt):  set logfile=d:\ping.txt  set /p Logfile=  date /t >%logfile%  time /t 》%logfile%  for /f "delims=. tokens=1,2,3" %%i in ("%startIP%") do set networkAdd=%%i.%%j.%%k  for /f "delims=. tokens=4" %%i in ("%startIP%") do set startHostAdd=%%i  for /f "delims=. tokens=4" %%i in ("%endIP%") do set endHostAdd=%%i  :next  if %startHostAdd% GTR %endHostAdd% goto finish  echo Pinging %networkAdd%.%startHostAdd%  ping -n 2 -w 2 %networkAdd%.%startHostAdd% >nul  if errorlevel 1 goto fail  if errorlevel 0 goto success  :success  echo successful!  echo %networkAdd%.%startHostAdd% is reachable 》%logfile%  goto counter  :fail  echo Fail!  echo %networkAdd%.%startHostAdd% is NOT reachable! 》%logfile%  goto counter  :counter  Set /a startHostAdd = StartHostAdd + 1  goto next  :finish  echo Finished ping  pause
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部