Needfull Ping Script

Have you ever had the problem that you needed to know what ip address your iphone or dreambox or any other small device got from dhcp but you have no access to a console or network config application. I wrote down a small shell script which does the work for you simply call it with a selected ip base and a start ip like:

pingrange.sh 102.168.0. 112 yes

This will start a ping session where the script iterates through the ip addresses 102.168.0.112 to .254 and shows you if a device is active or inactiv. The yes behind tells the script to abort if a device answers on an ip address. Skip the yes parameter and the script will scan the fully range given. Copy code from here to file and save as pingrange.sh if you want.

#!/bin/bash

usage()
{
echo ""
echo "pingrange copyright 2008 by Jörg Weis"
echo "see my blog on https://joergweis.wordpress.com"
echo "free under GPL License"
echo ""
echo "Usage: pingrange.sh "
echo ""
echo "Example: pingrange.sh 192.168.0. 110"
echo " this will start pinging at 192.168.0.110"
echo " and will loop until 254"
echo "Example: pingrange.sh 192.168.0. 110 yes"
echo " same as above but script will halt if an"
echo " ip is responding."
echo ""
echo "Have fun, bye, bye Admin"
echo ""
}

if [ "$1" = "" ]
then
usage
exit 1
fi

baseip=$1
stopOnActive=no

if [ "$3" != "" ]
then
stopOnActive=yes
fi

ipStart=$2
while [ true ]
do
if [ $ipStart -eq 254 ]
then
break
fi
ping -t 1 $baseip$ipStart > /dev/null
ret=$?
if [ $ret -eq 0 ]
then
echo "$baseip$ipStart is responding - AKTIV"
if [ "$stopOnActive" = "yes" ]
then
break
fi
else
echo "$baseip$ipStart is not responding - INAKTIV"
fi
ipStart=`expr $ipStart + 1`
done

exit $?

Have fun.

Advertisements

2 Gedanken zu “Needfull Ping Script

  1. Reducing the amount of fat in the diet is therefore the most effective
    way to reduce calorie intake. These toughened men could march through the thickest and wildest
    jungles for 24 hours straight on nothing more than a handful of seeds and some water.
    Chia seeds are sold in some supermarkets and online.

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s