Display a List of Open Network Connections on the Mac OS X Desktop
Using GeekTool and lsof, you can display an automatically updated list of open network connections directly on a Mac OS X desktop. This is tip is a “safe” alternative to the previously mentioned open_ports utility.
The problem with installing and using open_ports is that it is a third party script running as root, and for many users that is unacceptable. Here is a method that is native to Mac OS X and doesn’t even require root access to watch network connections:
First, if you want to discard the GeekTool portion and just get a quick look at open connections, you can quickly list all open network connections with:
lsof -i | grep -E "(LISTEN|ESTABLISHED)"
You could also combine this with the ‘watch’ utility and just keep an eye on open connections in a terminal window.
That portion of the tip has been covered here before regarding lsof, but the next part is geared specifically for GeekTool because it allows a constantly refreshed list of active connections to overlay against your desktop background picture.
Displaying a Active Network Connections on the Mac OS X Desktop
In order to do this, you’ll need to install GeekTool, it’s a free download and is a great addition to any advanced Mac users toolkit.
Assuming you have now downloaded and installed GeekTool, it will appear in your System Preferences. Here is the setup procedure now:
- Click on “Shell” and drag it to the desktop, resize it to a reasonable area
- Using the Properties editor, name the newly dragged Shell to something like “Show Connections”
- Under “Command” paste the following:
- Set your refresh rate to something reasonable, I chose 3 seconds but you can do whatever you want
- Adjust the font, font color, and font size in accordance to your desktop wallpaper
lsof -i | grep -E "(LISTEN|ESTABLISHED)" | awk '{print $1, $8, $9}'
You will immediately see a printed list of active network connections on your Mac desktop that automatically updates itself, just like the screen shot at the top of this article. No third party scripts or root access required. The GeekTool script comes from the comments on the MacWorld article about open_ports that they didn’t test. Very nice!
This network is very bad .10sakand colligh uftter disconnet on my fon. / or fon colling uftter sakand is one weya.
I just can’t get this one to work. If I only type in “lsof” with no additional options, it is ok. as soon as I add anything more (even just “lsof -i”) it fails. I tried with other simple shell commands as well and as soon as I add a space, the commands fail in GeekTool. Any thoughts?
[…] yet powerful tool without the complexity or the learning curves related to compiling and using the command line tools lsof, watch, open_ports, or wireshark. Highly recommended. stLight.options({ […]
I’d like to see the Bps for each established connection. I often am wanting to know what processes are consuming what bandwidth on my machine
Proper way to do this is to issue netstat -a -f inet
And why exactly is that? The cmd you gave, shows 1/3 of the info ‘lsof -i’ gives. You must spend twice the time to read half the info.
This will get even easier with Lion. See “nettop”
Not sure though. Nettop pulls info all the time. I’m sure if you can manipulate it. It’s also much more stressful compared to lsof. At least the manpage says so…
Great script! I like this one more than openports anyway, it’s simpler to read
Thank You