EASIEST BEST WAY
#################
This has the positive of just giving you the IP on 1 line, no other garbage and it has worked for year (2 for me and counting, im sure its more, I just haven’t started counting then)
Just remember icanhazip. “I can has IP” with a Z.
# curl www.icanhazip.com 234.234.234.234
or
# wget -O - www.icanhazip.com ..snip.. 234.234.234.234
The snip is there because you get extra output:
There will be extra output of the progress bar with wget, to make it go away
# wget -O - www.icanhazip.com > myip # cat myip
or simpler
# wget -O myip www.icanhazip.com # cat myip123
The progress bar goes to STDerr which is 2> which we dont use, we use > so it doesnt save to myip
Another way
# wget -nv -O 0 www.icanhazip.com
But that still also has some output, so again can negate the STDerr output like this
# wget -nv -O 0 www.icanhazip.com > myip # cat myip
With mypublicip.com
#####################
mypublicip has extra output on its html website unlike Icanhazip
Note you will have alot of extra text, your ip will be there
You can use it with my IP GREP tool to just single out the ip. (Here is the grep line: http://www.infotinks.com/grepfind-ips-in-a-file/)
# curl www.mypublicip.com
or
# curl www.mypublicip.com | grep -E -o '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
or
# wget -O - www.mypublic.com
or
# wget -O - www.mypublic.com | grep -E -o '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
or
# wget -O - www.mypublic.com > myip # cat myip
or
# cat myip | grep -E -o '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
or
# wget -O myip www.mypublic.com # cat myip
or
# cat myip | grep -E -o '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
MANY OTHER WAYS EXIST!