#! /bin/sh
#Script get_ip shows you the ip address of any interface
#(c) by Helmut 2009 (newbiefan at wl500g.info)
#Licence: GNU GPL2
#Contact: hirau@gmx.at
#Syntax: getip interface (where interface is br0.......)

interfaces=`/sbin/ifconfig | grep "Link encap" | awk '{print $1}'| awk -F: '{print $1}'`
ok=false

if [ -z "$1" ] ; then
  echo "Missing argument, syntax is: getip Name_of_interface"
  echo "valid interfaces are:" $interfaces
  exit 1
fi

 for valid_interface in $interfaces ; do
   if [ $1 = $valid_interface ] ; then
     ip=`/sbin/ifconfig $1 | grep "inet addr" | awk '{print $2}'| awk -F: '{print $2}'`
     ok=true
    if [ -z "$ip" ] ; then
       echo "Interface $valid_interface has no ip!"
     else
       echo "Interface $valid_interface has ip:" $ip
    fi
   fi
 done
if [ $ok = "false" ] ; then
  echo "wrong interface, use one of this:" $interfaces
fi
