Pages

Tuesday, May 19, 2009

Get the external IP of your router on the command line

Solution 1: wget and whatsmyip.com


#!/bin/sh
IP=`wget -q -O - http://whatismyip.com/automation/n09230945.asp`
echo $IP

Solution 2: wget and freeshell.org




#!/bin/sh
IP=$( wget -qO - http://cfaj.freeshell.org/ipaddr.cgi )
echo $IP

Solution 3: lynx and freeshell.org


#!/bin/sh
IP=$( lynx -dump http://cfaj.freeshell.org/ipaddr.cgi )
echo $IP

Solution 4: checkip.dyndns.org

My server sits behind a NAT router, so finding out my public IP address is a non-trivial task. I can use curl to poll checkip.dyndns.org for my current address:

curl -s checkip.dyndns.org


The current IP check returns the information in this format: <_head><_title>Current IP CheckCurrent IP Address: 216.239.39.99

Using cut, I can extract just the information that I need:

curl -s checkip.dyndns.org|cut -d ":" -f2|cut -d "<" -f1



Solution 5: whatismyip.org

echo External IP = $(wget -qO - http://whatismyip.org)

No comments: