Linux安全网 - Linux操作系统_Linux 命令_Linux教程_Linux黑客

会员投稿 投稿指南 本期推荐: 强烈推荐:Ylmf OS 3.0 正式版发布附迅雷高 XP系统下硬盘安装Fedora 14图文教程
搜索:
您的位置: Linux安全网 > Linux入门 > » 正文

批量Ping一段IP地址

来源: 未知 分享至:

 花了两个小时写了一个简单的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


Tags:
分享至:
最新图文资讯
1 2 3 4 5 6
验证码:点击我更换图片 理智评论文明上网,拒绝恶意谩骂 用户名:
关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 发展历史