How to get your public IP address in BASH
Posted: Thu Jan 12, 2012 9:30 am
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:
Note that if they change the format of whatsmyip.net it may break it, and please don't flood it with requests.
Code: Select all
wget -qO - -U “Firefox/3.0.15″ http://whatsmyip.net | grep "Your IP is" | sed 's/.*Your IP is: \(.*\)<.*>/\1/'