Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Find an Airport Extreme's WAN address in Terminal Network
I wrote a bash script that will find the current IP address of the WAN port on an Airport Extreme (and possibly other wireless routers) from the command line. It also works on a Linux-based computer, if you have the package net-smnp installed.

Go to the Advanced settings in your AirPort configuration, and select the Statistics tab. Make sure that 'Allow SNMP' is checked, and note the 'SNMP Community String -- it can be changed, but I would just keep it at public. Save your settings if they've been changed.

In the script below, the variable SNMPKEY needs to be changed if the 'SNMP Community String' is anything but public. You can also pass it from the command line if you wish. Here's the script:
#!/bin/sh

SNMPKEY="public"

if [ $# = 1 ] ; then
   SNMPKEY="$1"
fi
IFS=" "
set -- $(netstat -nr | egrep '^0.0.0.0|^default')
ROUTER=$2
set -- $(snmpwalk -Os -c "$SNMPKEY" -v 1 "$ROUTER" ipRouteNextHop.0.0.0.0)
set -- $(snmpwalk -Os -c "$SNMPKEY" -v 1 "$ROUTER" ipRouteNextHop.$4)

echo $4
[robg adds: I haven't tested this one.]
    •    
  • Currently 1.75 / 5
  You rated: 3 / 5 (16 votes cast)
 
[13,393 views]  

Find an Airport Extreme's WAN address in Terminal | 6 comments | Create New Account
Click here to return to the 'Find an Airport Extreme's WAN address in Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Find an Airport Extreme's WAN address in Terminal
Authored by: snoop on Dec 30, '09 01:15:21PM

An easier way to discover your WAN address is to use NAT-PMP. Just run the following command in Terminal...

$ dns-sd -X
Timestamp if External Address Protocol Internal Port External Port TTL
13:10:51.212 0 70.197.6.220 0 0 0 0



[ Reply to This | # ]
Find an Airport Extreme's WAN address in Terminal
Authored by: leamanc on Dec 30, '09 02:02:56PM
Good one. I wasn't aware of the dns-sd tool. Very nice!

[ Reply to This | # ]
Find an Airport Extreme's WAN address in Terminal
Authored by: drewk on Dec 30, '09 02:18:31PM

Why not this (in Terminal):

echo -e "local:\n$(ifconfig en0 | grep -oP 'inet \K(\d{1,3}\.){3}\d{1,3}')\n\npublic:\n$(curl -s sputnick-area.net/ip)";

Change "en0" to the desired interface on the Mac. en0 is the ethernet port.



[ Reply to This | # ]
Find an Airport Extreme's WAN address in Terminal
Authored by: jkreileder on Dec 31, '09 09:21:57AM

Why accessing an external site for information that already is available locally?



[ Reply to This | # ]
Find an Airport Extreme's WAN address in Terminal
Authored by: jcheshire on Dec 31, '09 06:28:33AM
Or, simpler still if you know that your connection is alive:
$ curl whatismyip.akamai.com

I usually include an empty echo at the end for the newline. Like this:
$ curl whatismyip.akamai.com; echo

It returns nothing but your IP after the standard headers. No need to parse HTML or the like.

[ Reply to This | # ]
Find an Airport Extreme's WAN address in Terminal
Authored by: digitalsushi on Dec 13, '10 08:23:06AM
I couldnt figure out how to make my mib resolve my 2009 airport extreme... but i have no idea how snmp works, either.
But this works for me. I don't figure this is specific to my general device (i think this is generic)

#!/bin/bash
ROUTER=`netstat -nr|awk '/^0.0.0.0/ {print $2}'`
gw=`snmpwalk -Os -c public -v 1 $ROUTER iso.3.6.1.2.1.4.21.1.7.0.0.0.0|awk '{print $4}'`
ip=`snmpwalk -Os -c public -v 1 $ROUTER iso.3.6.1.2.1.4.21.1.7.$gw|awk '{print $4}'`
echo $ip



[ Reply to This | # ]