See network connection speed via GeekTool

Aug 26, '09 07:30:04AM

Contributed by: kentmartin

I've written a quick script to print the network interface speeds, designed for use with GeekTool. In particular, this is very useful for seeing how fast your WiFi has connected. Create a new entry in GeekTool, and set it to a Shell action (how to do this varies depending on if you're using GeekTool 2.x or 3.x). In the Command window, enter the following code:

ifconfig en0 | grep inactive > /dev/null
RC=$?

if [ $RC -eq 0 ] ; then
  WIREDSTR="inactive"
else
  WIREDSTR="$(ifconfig en0 | grep media: | grep \( | sed 's/.*(//' | sed 's/ .*//' | sed 's/baseT/ MBit\/s/')"
fi

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | grep "AirPort: Off" > /dev/null
RC=$?

if [ $RC -eq 0 ] ; then
        WIRELESSSTR="inactive"
else
  /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | grep running > /dev/null
  RC=$?
  if [ $RC -eq 0 ] ; then
          WIRELESSSTR="$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | grep lastTxRate: | sed 's/.*: //' | sed 's/$/ MBit\/s/')"
  else
    WIRELESSSTR="disconnected"
  fi
fi

echo "Wireless:\t$WIRELESSSTR"
echo "Wired:\t\t$WIREDSTR"
Set the Refresh pop-up to whatever you prefer; the information provided is generally unchanging, so you can use a large refresh interval. If you'd prefer to run the above as a straight shell script, change the echo lines at the end to be echo -e .... Note that the script assumes en0 is wired Ethernet, and en1 is wireless networking.

[robg adds: I tested this, and it works as described. Note that this simply returns the speed of the connection, not the throughput. If you want to see network throughput, try this GeekTool script.]

Comments (6)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20090820163339755