Page 1 of 1

How to get your public IP address in BASH

Posted: Thu Jan 12, 2012 9:30 am
by Roken
I see this crop up from time to time, so thought I'd share. If you need to know your public IP address without visting a "whatsmyip" website in a browser (perhaps you need to use it in a script - or for your conky config), then this will do it:

Code: Select all

wget -qO - -U “Firefox/3.0.15″ http://whatsmyip.net | grep "Your IP is" | sed 's/.*Your IP is: \(.*\)<.*>/\1/'
Note that if they change the format of whatsmyip.net it may break it, and please don't flood it with requests.

Re: How to get your public IP address in BASH

Posted: Thu Jan 12, 2012 9:45 am
by Habitual
There's dozens of 'em, I used to collect 'em.

Code: Select all

curl -s http://icanhazip.com
curl -s http://ip.appspot.com
curl -s http://checkip.dyndns.org | grep -Eo '[0-9.]+'
curl http://ifconfig.me
curl http://www.chisono.it/ip.asp

Re: How to get your public IP address in BASH

Posted: Thu Jan 12, 2012 10:03 am
by Roken
Nice hobby ;)

I never came across any before

Re: How to get your public IP address in BASH

Posted: Thu Jan 12, 2012 1:28 pm
by mads
Good one! :)
And if you need to know your IP address:

Code: Select all

/sbin/ifconfig -a wlan0| grep addr: | awk '{print $2}' | sed 's/addr\://'

Re: How to get your public IP address in BASH

Posted: Thu Aug 09, 2012 10:03 am
by Habitual
loveisgod wrote:...You can get a good IP lookup tool for free from http://www.ip-details.com/ip-details-client/ it would also be useful for your collection.
I just gave out 5 free ones. :)