扫描有效的IP并打印到列表

时间:2015-12-16 10:53:58

标签: batch-file find

@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

out put是

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

1 个答案:

答案 0 :(得分:1)

通过解决方法,您可以找到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