Finding Out Your External IP Address from the Shell
I’m writing a script that needs to know the external IP address of the current machine (ifconfig only gives the local network address)
wget -q -O - http://checkip.dyndns.org | html2text \
| sed s/Current\ IP\ Address\:\ //
What this does is:
- hit http://checkip.dyndns.org, silencing wget’s output and redirecting the downloaded file to stdout
- parse the html page as text
- get rid of the cruft (I was thinking about using a complex regex here, but the IP address prefix seems less of a dependency concern than the actual dyndns service)
Categories: System Admin