IFACES_FILE=/etc/network/interfaces
RESOLV_FILE=/etc/resolv.conf
_OLD_IFS=$IFS
IFS=$'\n'
        
if [ `ifconfig | grep -v "^\s" | grep '^'$1'\b'` ]
then
    echo 'Enabled=true'
    ENABLED=true
fi

print_dns_list() {
	if [ $1 ]
	then
		echo $2=`echo $1|sed -r 's/\s+$//'|sed -r 's/^\s+//'|sed -r 's/\s+\b/,/g'`
	fi
}

print_conf_props() {
	_OLD_IFS=$IFS
	IFS=$'\n'
	_IS_IFACE_BLOCK=''
	_UserDNSServers=''
	_DNSServers=''
	for line in $(cat $IFACES_FILE)
	do
		if [ `echo "$line" | grep "^iface $1"` ]
		then
			_IS_IFACE_BLOCK=true
			test `echo $line | grep static` && echo DHCP_mode=0 || echo DHCP_mode=1
		elif [ $_IS_IFACE_BLOCK ] && ( [ `echo $line | grep ^iface` ] || [ `echo $line | grep ^auto` ] )
		then
			unset _IS_IFACE_BLOCK
		elif [ $_IS_IFACE_BLOCK ] && [ `echo $line|grep '^\s*dns-nameservers '` ]
		then
			_UserDNSServers=`echo $line|sed -r 's/^\s+//'|cut -d' ' -f2-`
			break
		fi
	done
	for line in $(cat $RESOLV_FILE|grep -v '^\s*#'|grep -v '^\s*;'|grep $1|awk '{print $2}')
	do
		if [ -z `echo $_UserDNSServers|grep -E "\b$line\b"` ]
		then
			_DNSServers=$_DNSServers' '$line
		fi
	done
	print_dns_list $_UserDNSServers UserDNSServers
	print_dns_list $_DNSServers DNSServers
	IFS=$_OLD_IFS
}

for line in $(ifconfig $1)
do
	if [ `echo $line|grep 'inet addr:'` ]
    then
		echo 'IP='`echo $line|grep -o 'inet addr:[^ ]*'|cut -d':' -f2`
		echo 'BroadcastAddress='`echo $line|grep -o 'Bcast:[^ ]*'|cut -d':' -f2`
		echo 'SubnetMask='`echo $line|grep -o 'Mask:[^ ]*'|cut -d':' -f2`
	fi
	if [ `echo $line|grep 'Link encap:'` ]
	then
		echo "MACaddress=`echo $line|grep -o 'HWaddr.*'|cut -d' ' -f2`"
	fi
	if [ `echo $line|grep 'MTU:'` ]
	then
		echo 'MTU='`echo $line|grep -o 'MTU:[^ ]*'|cut -d':' -f2`
	fi
	if [ `echo $line|grep 'Metric:'` ]
	then
		echo 'Metric='`echo $line|grep -o 'Metric:[^ ]*'|cut -d':' -f2`
	fi
	if [ `echo $line|grep 'MULTICAST'` ]
	then
		echo 'Multicast=true'
		MULTICAST=true
	fi
	if [ `echo $line|grep 'BROADCAST'` ]
	then
		echo 'Broadcast=true'
		BROADCAST=true
	fi
done
echo "Connected=$(test `ifconfig $1 | grep RUNNING` && echo true || echo false)"
echo "Gateway=$(route -n |grep $1| head -n 1 |awk '{print $2}')"
echo "Hostname=`hostname`"
print_conf_props $1
if [ -z $MULTICAST ]
then
	echo 'Multicast=false'
fi
if [ -z $BROADCAST ]
then
	echo 'Broadcast=false'
fi
if [ -z $ENABLED ]
then
	echo 'Enabled=false'
fi
IFS=$_OLD_IFS
