Sometimes you may need to know your public IPv4 address. If you have an open browser window you may go to https://www.whatismyip.com/ or to http://canihazip.com/. However, I prefer the latter for two reasons:
- It has a cleaner and simpler interface: it just shows your IP address.
- Has a script friendly version: http://canihazip.com/s which just prints your IP in text/plain.
So to get your public IP address from a shell:
$ IP=$(curl -s http://canihazip.com/s)
or
$ IP=$(wget -qO - http://canihazip.com/s)
Unfortunately, neither of the above mentioned sites work for IPv6 addresses.