找回密码
 开放注册

QQ登录

只需一步,快速开始

微信登录

微信扫码,快速开始

搜索
查看: 1218|回复: 0

批量Ping一段IP地址

[复制链接]

155

主题

15

回帖

360

牛毛

一级牛人

积分
360
发表于 2011-9-28 15:20:55 | 显示全部楼层 |阅读模式 来自 河北省石家庄市
  花了两个小时写了一个简单的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:   tomfxue@gmail.com                                                  *
  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
本文由:SKF轴承 http://wwww.9-zc.com 整理发布
您需要登录后才可以回帖 登录 | 开放注册

本版积分规则

帮助|Archiver|小黑屋|通信管理局专项备案号:[2008]238号|NB5社区 ( 皖ICP备08004151号;皖公网安备34010402700514号 )

GMT+8, 2025-4-27 08:16 , Processed in 0.150640 second(s), 33 queries .

Powered by Discuz! X3.5

快速回复 返回顶部 返回列表