#!/bin/bash numDevices=0 for x in `/sbin/ifconfig | grep Link | awk '{print $1}' | sort | egrep -v 'inet6|lo'` do #MAC=$(/sbin/ifconfig $x | grep "Link" | egrep -v inet6\|lo | awk '{print $5}') #IP=$(/sbin/ifconfig $x | grep "inet addr" | cut -d: -f2 | cut -d' ' -f1) #SPEED=$(/sbin/ethtool $x 2>/dev/null | grep "Speed" | cut -d: -f2 | sed 's/^[ \t]*//') #LINK=$(/sbin/ethtool $x 2>/dev/null | grep "Link detected" | cut -d: -f2 | sed 's/^[ \t]*//') if [[ $numDevices -eq 0 ]]; then echo "{" echo " \"data\":[" fi if [[ -n "$x" ]]; then echo " { \"{#IFNAME}\":\"$x\" }," #echo -e $x"\t\t"$MAC"\t"$IP"\t"$SPEED"\t"$LINK fi let "numDevices++" done if [[ $numDevices -gt 0 ]]; then echo " ]" echo "}" exit 0 else exit 1 fi