#!/bin/bash

FIJA=`cat /proc/net/dev | cut -f1 -d: | grep eth`
WIFI1=`cat /proc/net/dev | cut -f1 -d: | grep wlan`
WIFI2=`cat /proc/net/dev | cut -f1 -d: | grep ath`
WIFI3=`cat /proc/net/dev | cut -f1 -d: | grep ra`

AAA=`/sbin/ifconfig $FIJA | grep 'inet ' | awk '{print $2}' | sed "s/addr://"`
BBB=`/sbin/ifconfig $WIFI1 | grep 'inet ' | awk '{print $2}' | sed "s/addr://"`
CCC=`/sbin/ifconfig $WIFI2 | grep 'inet ' | awk '{print $2}' | sed "s/addr://"`
DDD=`/sbin/ifconfig $WIFI3 | grep 'inet ' | awk '{print $2}' | sed "s/addr://"`

if [ $AAA != "" ]; then
	IPLOCAL=$AAA
elif [ $BBB != "" ]; then
	IPLOCAL=$BBB
elif [ $CCC != "" ]; then
	IPLOCAL=$CCC
elif [ $DDD != "" ]; then
	IPLOCAL=$DDD
fi

case $LANG in
    es*) MSG1="Su IP <b>pública</b> es:"
		 MSG2="Su IP <b>local</b> es:";;
    gl*) MSG1="O seu IP <b>público</b> é:"
		 MSG2="O seu IP <b>local</b> é:";;
    *)   MSG1="Your <b>public</b> IP is:"
		 MSG2="Your <b>local</b> IP is:";;
esac    

IPPUBLICA=$(wget -q -O - checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
# OUTRA OPCIÓN
# IPPUBLICA=$(wget http://www.whatismyip.com/automation/n09230945.asp -O - 2> /dev/null; echo)

if [ $IPPUBLICA = $IPLOCAL ]; then
	zenity --info --text="$MSG1\n\n<b>       $IPPUBLICA</b>"
else
	zenity --info --text="$MSG1\n<b>       $IPPUBLICA</b>\n\n$MSG2\n<b>       $IPLOCAL</b>"
fi
