Here’s my code snippet for getting the current external IP address.
Method 1 (using curl):
This one requires curl to be installed.
curl -s http://checkip.dyndns.org | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'
Method 2 (using wget):
wget -q -O- http://checkip.dyndns.org | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'
I recommend the second because it should work on any system.
Of course you can replace Dyndns with any “IP get” page like http://whatismyip.com.
Great post! I see you started to like cURL
curl -L -s –max-time 10 http://checkip.dyndns.org | grep -Eo -m 1 ‘([[:digit:]]{1,3}.){3}[[:digit:]]{1,3}’
lynx -dump http://www.formyip.com/ | awk “/IP is/” | awk {‘print $4′}
wget -O – -q icanhazip.com