扫描有效的 ip 并打印到列表
Scan for valid ip and prints to list
@echo off
set /a n=0
:repeat
set /a n+=1
echo 192.168.250.%n%
ping -n 1 -w 500 192.168.250.%n% | FIND /i "Reply">>ipaddresses.txt
if %n% lss 254 goto repeat
type ipaddresses.txt
输出是
Reply from 192.168.250.1: bytes=32 time<1ms TTL=64
Reply from 192.168.250.11: bytes=32 time<1ms TTL=255
Reply from 192.168.250.13: bytes=32 time=1ms TTL=64
Reply from 192.168.250.15: bytes=32 time<1ms TTL=64
Reply from 192.168.250.16: bytes=32 time<1ms TTL=64
Reply from 192.168.250.20: bytes=32 time<1ms TTL=64
所以我需要一个有效的 ip 列表。我以这段代码为例。这是一个很好的批处理工具,但它输出了整个回复,我只需要 ip,我是批处理的菜鸟,但我正在努力学习。关于如何删除 Reply from : bytes=32 time<1ms TTL=64
的任何想法?并保留 ip
通过您的解决方法,您会发现 batch beginner bug
试试这个
@echo off
(
FOR /L %%N in (1 1 254) DO (
echo TEST: 192.168.250.%%N
FOR /f "tokens=1,3 delims=: " %%A IN ('ping -n 1 192.168.250.%%N ^| findstr "Reply"') DO ECHO Reply from: %%B
)
) >scan.txt
@echo off
set /a n=0
:repeat
set /a n+=1
echo 192.168.250.%n%
ping -n 1 -w 500 192.168.250.%n% | FIND /i "Reply">>ipaddresses.txt
if %n% lss 254 goto repeat
type ipaddresses.txt
输出是
Reply from 192.168.250.1: bytes=32 time<1ms TTL=64
Reply from 192.168.250.11: bytes=32 time<1ms TTL=255
Reply from 192.168.250.13: bytes=32 time=1ms TTL=64
Reply from 192.168.250.15: bytes=32 time<1ms TTL=64
Reply from 192.168.250.16: bytes=32 time<1ms TTL=64
Reply from 192.168.250.20: bytes=32 time<1ms TTL=64
所以我需要一个有效的 ip 列表。我以这段代码为例。这是一个很好的批处理工具,但它输出了整个回复,我只需要 ip,我是批处理的菜鸟,但我正在努力学习。关于如何删除 Reply from : bytes=32 time<1ms TTL=64
的任何想法?并保留 ip
通过您的解决方法,您会发现 batch beginner bug
试试这个
@echo off
(
FOR /L %%N in (1 1 254) DO (
echo TEST: 192.168.250.%%N
FOR /f "tokens=1,3 delims=: " %%A IN ('ping -n 1 192.168.250.%%N ^| findstr "Reply"') DO ECHO Reply from: %%B
)
) >scan.txt