Labels

Arduino (1) Bugs (3) C (1) Install (3) Linux (25) Maths (1) Python (11) Raspberry Pi (4)

Thursday, 2 July 2015

Basic script to ping all hosts online.

This shell script is a script that pings all the hosts between 192.168.0.1-254. It returns if they are online or not.

#!/bin/sh
for i in `seq 1 254`
do
  ping -c 1 -t 1 192.168.0.$i | grep "64 bytes" &
  sleep 0.1
done

This takes 26 seconds.

If you run the code like this it is significantly slower as the ping command runs in the foreground. To background it you need to add a & at the end of it.

#!/bin/sh
for i in `seq 1 254`
do
  ping -c 1 -t 1 192.168.0.$i | grep "64 bytes" amp;
  sleep 0.1
done