Get your ip

10:41 pm in CentOS, Debian, Fedora by emran

#!/bin/bash
# get ip
/sbin/ifconfig $1 | grep inet | awk ‘{print $2}’ | sed ‘s/^addr://g’

To get your Internet address if you are behind a NAT:

## The -n option retrieves the Internet IP address

## if you are behind a NAT

if [ "$1" = "-n" ]

then ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)

else if=$1 ## specify which interface, e.g. eth0, fxp0

system=$(uname)

case $system in FreeBSD)

sep=”inet “ ;;

Linux) sep=”addr:” ;;

esac temp=$(ifconfig $if)

temp=${temp#*”$sep”}

 ip=${temp%% *}

fi

printf “%s\n” “$ip”

### CFAJ ###