您的位置:首页 > 其它

ping 一个IP段可用IP批处理文件

2014-06-17 23:15 239 查看
使用场景:知道一个IP端都属于某个公司,但不知道有哪些IP可用

用法: pingseg.bat 127.0.0

或 pingseg.bat 127.0.0 > 127.0.0.txt

批处理文件(pingseg.bat)

@echo off
setlocal enabledelayedexpansion
;:Timeout for ping command in milliseconds
Set _t0=500
:start IP (last number)
Set _t1=1
:ending IP (last number)
Set _t2=254
if "%1"=="" (
echo ping a ip segment xxx.xxx.xxx.*
echo usage: pingseg xxx.xxx.xxx
goto:eof
) else (
Set _t4=%1.
)
echo start pinging..., it may take several minutes
echo available ip are:
for /L %%I in (%_t1%,1,%_t2%) do set _t3=%%I & (ping %_t4%%%I -n 1 -w %_t0% >nul
) & call:_e!errorlevel!
echo All IPs tested
:clear the temp variables that were used
for /L %%I in (0,1,4) do set _t%%I=
goto:eof
:_e0
echo %_t4%%_t3%
goto:eof
:_e1
goto:eof


要输出以 | 分隔的IP列表

@echo off
setlocal enabledelayedexpansion
;:Timeout for ping command in milliseconds
Set _t0=500
:start IP (last number)
Set _t1=1
:ending IP (last number)
Set _t2=254
if "%1"=="" (
echo ping a ip segment xxx.xxx.xxx.*
echo usage: pingseg xxx.xxx.xxx
goto:eof
) else (
Set _t4=%1.
)
echo start pinging..., it may take several minutes
echo available ip are:
for /L %%I in (%_t1%,1,%_t2%) do set _t3=%%I& (ping %_t4%%%I -n 1 -w %_t0% >nul
) & call:_e!errorlevel!
echo.
echo All IPs tested
:clear the temp variables that were used
for /L %%I in (0,1,4) do set _t%%I=
goto:eof
:_e0
echo|set /p="%_t4%%_t3%|"
goto:eof
:_e1
goto:eof
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: