IP Address info from Router

Posted in Internet by parvez 2075 days ago

Installed lynx and added egrep and sed magic to get the IP Address information from my CISCO Router.

/opt/local/bin/lynx -dump -auth=admin:PASSWORD -accept_all_cookies | egrep -E ":  " | sed "s/   :  //g" | awk 'NR==3'

I did not want to use whatismyip.com to get my IP Address. Prefer to get the info locally.



User Avatar
matt 2076 days ago
Note: For this to work correctly you have to have lynx installed in `/opt/local/bin` - i.e. you have to install it via macports:

If you don't want to go to the trouble of getting MacPorts, you can install Lynx on it's own, and modify the script - most likely to `/usr/local/bin`
User Avatar
parvez 2071 days ago
Thanks Matt for the additional info!
User Avatar
dylanjnsn022 1986 days ago
you jus do this


ifconfig | grep 'broadcast'| awk '{print $2 }'


does the same thing
User Avatar
parvez 1984 days ago
@dylanjnsn022 That does not give you the public IP address.
User Avatar
parvez 1984 days ago
User Avatar
GYLLIWER 1974 days ago
User Avatar
cessnakid 1847 days ago
User Avatar
hawk 1735 days ago
You don't need lynx for this, curl can do the job (and is installed on every mac).

Here is the command I'm using to get the IP from my NETGEAR WNDR3400v2 router running the firmware version V1.0.0.34_1.0.52

echo "IP address\n$(curl -u admin:password 2>/dev/null | egrep -iA 2 "ip address" | egrep -o '([0-9]{1,3}\.?){4}')"

You may need a different pattern to search for, so open the status page of your router's web interface and study the HTML source code. In my case, the relevant part looks like this:

Edit: Nevermind, the markdown on this site is broken.
User Avatar
ksb 1647 days ago
If you put your password in ~/.netrc ( see the curl manual page), then you may use

this command for a QWest or Century Link modem:

> curl -s --netrc

That gets you the raw text, then a grep for

> var wanInfNames = htmlDecodeStr

Gets you a line with all sorts of great things to know about the modem. I parsed

that with a little perl, and now I have a near-real-time external IP address.

Log in to comment or register here.