Monday, August 2, 2010

Gateway IP address

I'm building an 'evil-twin' script. It needs to find out which adapter (like eth0 or wlan0) I'm going to use as my upstream side, that will connect to the Internet. It also needs the gateway IP address.

The way to do that is with the route -n command (netstat -rn also works), then extract the data with grep and awk:

gatewayip=`route -n | grep 'UG[ \t]' | awk '{print $2}'`


notes: http://www.cyberciti.biz/faq/how-to-find-gateway-ip-address/

No comments:

Post a Comment