Ping a subnet by defining first three octets and return corresponding MAC Addresses for any IP addresses that respond to ICMP Ping on directly attached network.
You may have come across this requirement but I use it very often to update the inventory and status of my network. Something I maintain and find very useful to audit the network, find anomilies and know what is allocated to what. Also useful if you manage MAC Address filtering on your Router.
------------------- Begin of script ./multiping ----------------------
#!/bin/bash
echo "Usage: ./multiping [subnet e.g. 192.168.1]"
CURR=1
SUBNET="$1"
FILE=multiping.log
touch $FILE
function multiping() {
ping -c1 -t1 $SUBNET.$CURR 2>&1 >/dev/null
if [ "$?" -eq "0" ]; then
echo $(arp $SUBNET.$CURR) >> $FILE
fi
}
while [ $CURR -lt 255 ] ; do
multiping &
let CURR=$CURR+1
let MOD=$CURR%100
#this code is for prevent the saturation of the executable connections
if [[ $MOD -eq 0 ]]; then
wait
fi
done
wait
cat $FILE
rm $FILE
------------------- End of script ./multiping ----------------------
It is very much self explainatory but you can run it using below command to list the IP Addresses that respond with corresponding MAC Addresses.
./multiping.sh 192.168.0
You may have come across this requirement but I use it very often to update the inventory and status of my network. Something I maintain and find very useful to audit the network, find anomilies and know what is allocated to what. Also useful if you manage MAC Address filtering on your Router.
------------------- Begin of script ./multiping ----------------------
#!/bin/bash
echo "Usage: ./multiping [subnet e.g. 192.168.1]"
CURR=1
SUBNET="$1"
FILE=multiping.log
touch $FILE
function multiping() {
ping -c1 -t1 $SUBNET.$CURR 2>&1 >/dev/null
if [ "$?" -eq "0" ]; then
echo $(arp $SUBNET.$CURR) >> $FILE
fi
}
while [ $CURR -lt 255 ] ; do
multiping &
let CURR=$CURR+1
let MOD=$CURR%100
#this code is for prevent the saturation of the executable connections
if [[ $MOD -eq 0 ]]; then
wait
fi
done
wait
cat $FILE
rm $FILE
------------------- End of script ./multiping ----------------------
It is very much self explainatory but you can run it using below command to list the IP Addresses that respond with corresponding MAC Addresses.
./multiping.sh 192.168.0