We use static IP's in our environment and have a need to verify default router IP's from time to time. Can anyone recommend an extension attribute or script that would display the default router/gateway info?
Page 1 / 1
You can try the following
#!/bin/sh
activeDev=$(netstat -rn | awk '/default/{print $NF}')
if [ ! -z "$activeDev" ]; then
activePort=$(networksetup -listallhardwareports | grep -B1 "$activeDev" | awk -F': ' '/Hardware Port:/{print $NF}')
routerIP=$(networksetup -getinfo "$activePort" | awk '/Router:/{print $NF}')
echo "<result>$routerIP</result>"
else
echo "<result>No active network</result>"
fi
Worked like a charm. Thanks much.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.