निम्नलिखित स्क्रिप्ट को कहीं उपयोगी सहेजें। इसे आईपी पते के साथ कॉल करें जिसे आप परीक्षण करना चाहते हैं और यह आपको संबंधित मार्ग बताएगा।
#!/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
उदाहरण उपयोग
./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