#!/bin/bash

DIRICON="/usr/local/share/icons"

IPLOCAL=`ip -s route | cut -d" " -f12 | tail -n1`

if [ "$IPLOCAL" = "" ]; then

	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

fi

case $LANG in
    ca*) MSG1="La seva IP pública és:"
	 MSG2="La seva IP local és:"
	 MSG3="La meva IP";;
    es*) MSG1="Su IP pública es:"
	 MSG2="Su IP local es:"
	 MSG3="Mi IP";;
    gl*) MSG1="O seu IP público é:"
	 MSG2="O seu IP local é:"
	 MSG3="O meu IP";;
    *)   MSG1="Your public IP is:"
	 MSG2="Your local IP is:"
	 MSG3="My IP";;
esac    

IPPUBLICA=$(curl http://ipecho.net/plain 2>/dev/null)


	if [ "$IPPUBLICA" = "" ]; then
		IPPUBLICA=$(wget -q -O - checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
	fi

	if [ "$IPPUBLICA" = "" ]; then
		IPPUBLICA=$(curl ifconfig.me/ip)
	fi

echo $MSG1$IPPUBLICA
echo $MSG2$IPLOCAL
echo "http://localhost:8000/"
python -m SimpleHTTPServer
