Send a ping to each IP on a subnet

后端 未结 13 1206
时光说笑
时光说笑 2020-12-07 10:21

Is there a command line based way to send pings to each computer in a subnet? Like

for(int i = 1; i < 254; i++)
    ping(192.168.1.i);

t

13条回答
  •  轮回少年
    2020-12-07 10:37

    This is a modification of @david-rodríguez-dribeas answer above, which runs all the pings in parallel (much faster) and only shows the output for ip addresses which return the ping.

    export COUNTER=1
    while [ $COUNTER -lt 255 ]
    do
        ping $1$COUNTER -c 1 -w 400 | grep -B 1 "Lost = 0" &
        COUNTER=$(( $COUNTER + 1 ))
    done
    

提交回复
热议问题