Watch All Open Network Connections in Mac OS X with Open_Ports
You can watch all open network connections for both incoming and outgoing transfers using a free command line utility called open_ports.sh. Open_Ports is much more useful than using lsof to list open internet connectionsbecause it provides extensive network information in a very easy to read format, including what program or process is opening the connection, which port and user, the number of connections per process, the hostname being connected to, the country, and even the city.
Additionally, open_ports shows you all of your open ports listening for connections, again with information about the application, user, port number and name, and even the service IP range. All of the output is color coded, a red background signifies the process is owned by root, red text means the IP address doesn’t correspond to a domain name, blue means the IP matches several domain names, and green text means the protocol is encrypted.
Installation requires some experience with the command line, but chances are if you want an application like this then that won’t be an issue. Here we go…
Installing Open_Ports in Mac OS X
These are are the installation instructions directly from the developers page at Lunds University in Sweden, they have been verified to work in Mac OS X 10.6.8:
Warning: This is a bash script that runs as root that downloads other scripts from the web. This has obvious potential security issues and if you are not comfortable with that or you are in a delicate network environment, this is not recommended to use. The script works as intended, and you can verify the source of the bash script yourself if you want, but if you have any questions or hesitation about running a third party script as root then you may want to use an alternate method to watch open connections, using lsof for example. Proceed at your own risk.
- Fetch the install-script from
http://fileadmin.cs.lth.se/cs/Personal/Peter_Moller/scripts/open_ports_install.sh- Start a terminal
- Become root: if you are a normal user, type
sudo adminusernamne
and thensudo -i
if you are an admin-user, typesudo -i
- Set access rights for the install script:
chmod 755 open_ports_install.sh
(you must locate it)- Run the script:
./open_ports_install.sh
- The installation is normally quick. For Linux, that all. On a Mac it ands with GeekTool being opened. To install it, double-click it’s .PrefPane
- In GeekTool: click the icon named ”Shell” and drag it to an empty part of the desktop (must be free of windows). Size it as well.
- A ”Properties”-window opens. What you need to enter is:
- Command: open_ports.sh
- Refresh every: 120 s
- Change font to a monospace-one (I’m using Menlo and white font color)
- Now you may close GeekTool
The other great thing about open_ports is that the Mac OS X version is built to be used in GeekTool, so you can display the output on your Mac desktop. If you’re going to use it through GeekTool, I would suggest using a more plain background picture otherwise the text is hard to read, this is how it looks against the OS X Lion Galaxy wallpaper.
If you want to unintsall open_ports from Mac OS X, use the following commands as root:
launchctl stop se.lth.cs.open_ports
launchctl unload /Library/LaunchDaemons/se.lth.cs.open_ports.plist
Then you can delete the scripts:
rm -rf /usr/bin/open_ports.sh (the script)
rm -rf /Library/LaunchDaemons/se.lth.cs.open_ports.plist (the gather control)
rm -rf /Library/cs.lth.se/OpenPorts (the data files)
In case you were wondering, there is also a Linux version available. I came across this awesome utility on MacWorld, but MacWorld didn’t actually test the script to verify that it works, but I can confirm that it definitely does.
[…] are other ways to see similar information from the command line, including lsof, open_ports, and then, branching away from the command line a bit you can use GeekTool with lsof to have a list […]
[…] or the learning curves related to compiling and using the command line tools lsof, watch, open_ports, or wireshark, and is therefore highly recommended for anyone who is interested in seeing this kind […]
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
Installed this on an ubuntu machine. The install script blasted root crontab and added 1 line to it. All my scheduled jobs were lost.
Be advised this may look cool, but whoever put it together did not do a very good job at making it standardized.
[…] 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. […]
I tried, many times, but the download has failed.
I received that message:
Checksum does NOT match!! Installation aborted!
Anyone had this problem?
I will try again later.
Same happened with me
Thank goodness OS X is UNIX under the hood~
-Chris
FOM
[…] Read the entire article here: Watch All Open Network Connections in Mac OS X with Open_Ports. […]
everything fine until Properties-window opens
i get a dark grey screen which says “Geeklet Settings”
but no way to enter info.
RTFM
jimjmcn, after GeekTool has been installed and you are in System Preferences, click and hold on the “Shell” icon and drag it to your Mac OS X desktop, this creates the ‘geeklet’ where the script is ultimately displayed, and this is what you are adjusting the settings for.
Drag the shell to the desktop or else you have nothing to display the command output to.
Very cool and super handy tool mate, thanks so much for the quick tutorial about it
From a university or not, I’m not going to run a random bash script as root in the background. Good concept but I will stick with lsof for security reasons.
Because reading a 50 line script is hard?
People are generally fearful of things they don’t understand. It’s a simple script and very easy to follow exactly what it’s doing, after viewing the source I have no qualms about running it.
Not crazy about this script. First of all Dean, the 50 line script is the install script. The open_ports.sh script is 728 lines.
Unfortunately the script downloads a new version of itself when one is available. This means that even if you know what the script does, it could change next time it’s updated. You’re relying on the goodwill of the author. Don’t forget – the script runs as root. Would you give some guy you’ve never met the keys to your front door and the code for the alarm?
I went through about 1/2 the script thinking I could remove the questionable portions but honestly I don’t have the time.
Not worth the risk.
Asad, you may find this similar trick much more to your liking, it requires no script downloads and doesn’t even run as root:
https://osxdaily.com/2011/07/11/display-a-list-of-open-network-connections-on-the-mac-os-x-desktop/
Very nice Will. Setup and working. Thanks!