Send a ping to each IP on a subnet

后端 未结 13 1205
时光说笑
时光说笑 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:42

    #!/bin/sh
    
    COUNTER=$1
    
    while [ $COUNTER -lt 254 ]
    do
     echo $COUNTER
     ping -c 1 192.168.1.$COUNTER | grep 'ms'
     COUNTER=$(( $COUNTER + 1 ))
    done
    
    #specify start number like this: ./ping.sh 1
    #then run another few instances to cover more ground
    #aka one at 1, another at 100, another at 200
    #this just finds addresses quicker. will only print ttl info when an address resolves
    

提交回复
热议问题