External IP address

Paul Dickson plug-devel@lists.PLUG.phoenix.az.us
Fri Apr 8 11:05:03 2005


On Thu, 07 Apr 2005 21:38:29 -0700, Jeffrey Starr wrote:

> Since it seems my reply won't be seen on the list for some time, I
> suggest if you need the external IP, visit www.whatismyip.com. If you
> want do this in an automated way, you'll have to parse the HTML.


Thanks, I got that one (after I posted my message):

myip=$(curl -s http://www.whatismyip.com/| \
       grep "Your IP is"|sed -e 's/.* is \(.*\)<.*/\1/')
if [ -z "$myip" ]; then
    myip=$(curl -s http://pilipukas0.tripod.com/|grep REMOTE_ADDR| \
           sed -e "s/.* : \(.*\)/\1/")
fi
if [ -z "$myip" ]; then
    myip=$(curl -s http://www.swlink.net/~styma/REMOTE_ADDR.shtml| \
           sed -n -e "/\([0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+\)/p")
fi
if [ -z "$myip" ]; then
    echo "Unable to determine the external IP address."
fi

The last one will work on any web server that supports shtml.  Download
the page with the same URL, but substitute .html for the source.


	-Paul