Aşağıdaki komut dosyasını yararlı bir yere kaydedin. Test etmek istediğiniz IP Adresi ile çağırın ve size ilgili rotayı söyleyecektir.
#!/bin/bash
#
# Find the appropriate routing entry for a given IP address
########################################################################
########################################################################
# Calculate the base network address for a given addres and netmask
#
baseNet() {
local ADDRESS="$1" NETMASK="$2"
ipcalc -nb "$ADDRESS" "$NETMASK" | awk '$1=="Network:"{print $2}'
}
########################################################################
# Go
#
for IPADDRESS in "$@"
do
netstat -rn |
tac |
while read DESTINATION GATEWAY GENMASK FLAGS MSS WINDOW IRTT IFACE
do
NSBASENET=$(baseNet "$DESTINATION" "$GENMASK")
IPBASENET=$(baseNet "$IPADDRESS" "$GENMASK")
if test "X$NSBASENET" = "X$IPBASENET"
then
if test '0.0.0.0' = "$GATEWAY"
then
echo "Matches $DESTINATION with netmask $GENMASK directly on $IFACE"
else
echo "Matches $DESTINATION with netmask $GENMASK via $GATEWAY on $IFACE"
fi
break
fi
done
done
# All done
#
exit 0
Örnek kullanım
./what-route.sh 10.0.5.6
Matches 0.0.0.0 with netmask 0.0.0.0 via 10.0.2.2 on eth0
./what-route.sh 10.0.2.6
Matches 10.0.2.0 with netmask 255.255.255.0 directly on eth0