5

IP Address info from Router

Posted in Internet by parvez 1013 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 http://192.168.1.1/Status_Router.asp | 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.

Thanks!

Comments

User Avatar
matt 1013 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 1008 days ago
Thanks Matt for the additional info!
User Avatar
dylanjnsn022 923 days ago
you jus do this

********************************************

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

********************************************

does the same thing
User Avatar
parvez 921 days ago
@dylanjnsn022 That does not give you the public IP address.
User Avatar
parvez 921 days ago
User Avatar
GYLLIWER 911 days ago
5+
User Avatar
cessnakid 784 days ago
nice
User Avatar
hawk 672 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 http://192.168.1.1/RST_st_dhcp.htm 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 585 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 http://192.168.0.1/modemstatus_home.html

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.