13

Colored Netstat

Posted in System by un1xt3r 559 days ago

Inspired by the Colored Calendar geeklet which highlighted the current day. This geeklet colors the output of netstat.

Desiring to keep things as flexible as possible, this geeklet includes a script which acts like a wrapper to the netstat command while adding color to lines according to the currently listed connection status. This way the output of colornetstat can be easily manipulated from the geeklet's run command. Finally, it should be noted that the geeklet contains an example filtering the output through grep.

colornetstat script:

#!/bin/sh
# colorize netstat output
color_red=`echo "33[0;31m"`
color_green=`echo "33[0;32m"`
color_yellow=`echo "33[0;33m"`
color_blue=`echo "33[0;34m"`
color_purple=`echo "33[0;35m"`
color_cyan=`echo "33[1;36m"`
no_color=`echo "33[0m"`
netstat ${@} |sed -e "s/^.* ESTABLISH.*$/${color_green}&${no_color}/; s/^.* LIST.*$/${color_cyan}&${no_color}/; s/^.* *.WAIT$/${color_red}&${no_color}/; s/^.* CLOSING$/${color_red}&${no_color}/; s/^.* SYN.*$/${color_yellow}&${no_color}/; s/^.* FIN.*$/${color_yellow}&${no_color}/; s/^.* *.ACK/${color_yellow}&${no_color}/"

The script was developed and tested on Mac OS X 10.6.4.

Update: 08/05/2010

  • Changed color of WAIT and CLOSE states from yellow to red
  • Made some colors darker

Geeklet files to download

Comments

Log in to comment or register here.