Re: check my own ip number ?

From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 11/17/05


Date: Wed, 16 Nov 2005 23:31:26 -0500

On 2005-11-16, Dan Mercer wrote:
>
> "Thomas Bosch" <t-bosch@versanet.de> wrote in message news:dlf3t9$1u8$1@news01.versatel.de...
>: or:
>: lynx -dump http://checkip.dyndns.org|cut -d ":" -f 2|sed -e 's/|head -n 1
>
> None of these web based solutions will work if you are behind a NAT router/firewall.
> Now that may be the IP you are looking for, though it's unlikely you'll be able
> to do much with it.

    Many of the questions I see are looking for exactly that IP
    address. Many are looking for the lan address. That's why I wrote
    this script that gets whichever one you want:

## USAGE: ipaddr [-n]
if [ "$1" = "-n" ]
then
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)
else
  if=$1
  system=$(uname)
  case $system in
      FreeBSD) sep="inet " ;;
      Linux) sep="addr:" ;;
      *) echo "System not supported: $system"; exit 1;;
  esac
  temp=$(ifconfig $if)
  temp=${temp#*"$sep"}
  ip=${temp%% *}
fi

printf "%s\n" "$ip"

> What - no perl on your system?

    Lucky guy!

-- 
   Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
   Shell Scripting Recipes:     |  My code in this post, if any,
   A Problem-Solution Approach  |          is released under the
   2005, Apress                 |     GNU General Public Licence