平一个用户定义的IP地址范围与批次 [英] Ping a user defined IP-Range with batch
本文介绍了平一个用户定义的IP地址范围与批次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我工作的一所学校的项目,我想创造坪用户定义的IP范围,并写入成功坪到一个txt文件的批处理文件。
I'm working on a school project and I wanted to create a batch file that pings a user-defined IP-range and writes the successful pings to a txt file.
现在我被困在的
循环:
@echo off
SET /p IPRange=Bitte IP-Range eingeben(xxx.xxx.xxx) :
SET /p AnfangsIP=Bitte AnfangsIP des Bereiches eingeben :
SET /p EndIP=Bitte EndIP des Bereiches eingeben :
FOR /L %IP% (%AnfangsIP%,1,%EndIP%) DO (
ping -n 1 %IP-Range%.%IP% | find "TTL=" >nul
if errorlevel 1 (
echo %IP-Range%.%IP% not reachable
) else (
echo %IP-Range%.%IP% reachable
)
)
pause>nul
批处理文件与这些参数执行:IP范围,起始IP地址,结束IP地址。我的目标是做一个为
循环,增加变量%IP%
每次循环。从启动IP地址
到结束IP地址
。
The batch file is executed with these parameters: IP range, start IP-address, end IP-address. My goal is to make a for
loop that increments the variable %IP%
every loop. From the start IP-address
to the end IP-address
.
我搜索的论坛,但目前只有单一的坪没有为整个IP范围。
I searched in the forum but there are just single pings not for a whole range of IPs.
推荐答案
试试这个:
@echo off
SET /p IPRange=Bitte IP-Range eingeben(xxx.xxx.xxx) :
SET /p AnfangsIP=Bitte AnfangsIP des Bereiches eingeben :
SET /p EndIP=Bitte EndIP des Bereiches eingeben :
FOR /L %%I IN (%AnfangsIP%,1,%EndIP%) DO (
ping -n 1 %IPRange%.%%I | find "TTL=" >nul
if errorlevel 1 (
echo %IPRange%.%%I not reachable
) else (
echo %IPRange%.%%I reachable
)
)
pause>nul
修改:补充输出实例的
C:\> test.bat
Bitte IP-Range eingeben(xxx.xxx.xxx) :127.0.0
Bitte AnfangsIP des Bereiches eingeben :0
Bitte EndIP des Bereiches eingeben :7
127.0.0.0 not reachable
127.0.0.1 reachable
127.0.0.2 reachable
127.0.0.3 reachable
127.0.0.4 reachable
127.0.0.5 reachable
127.0.0.6 reachable
127.0.0.7 reachable
这篇关于平一个用户定义的IP地址范围与批次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文