Watch All Open Network Connections in Mac OS X with Open_Ports

Jul 9, 2011 - 20 Comments

Showing open ports on the Mac desktop

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.

  1. Fetch the install-script from
    http://fileadmin.cs.lth.se/cs/Personal/Peter_Moller/scripts/open_ports_install.sh
  2. Start a terminal
  3. Become root: if you are a normal user, type sudo adminusernamne and then sudo -i if you are an admin-user, type sudo -i
  4. Set access rights for the install script:
    chmod 755 open_ports_install.sh (you must locate it)
  5. Run the script:
    ./open_ports_install.sh
  6. 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
  7. 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.
  8. 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)
  9. 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.

Show open network connections on the Mac OS X Desktop

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.

.

Related articles:

Posted by: William Pearson in Command Line, Mac OS, Tips & Tricks

20 Comments

» Comments RSS Feed

  1. […] 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 […]

  2. […] 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 […]

  3. xristy says:

    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

  4. Anonymous says:

    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.

  5. […] 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. […]

  6. Diego Castilho says:

    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.

  7. Thank goodness OS X is UNIX under the hood~

    -Chris
    FOM

  8. […] Read the entire article here: Watch All Open Network Connections in Mac OS X with Open_Ports. […]

  9. jimjmcn says:

    everything fine until Properties-window opens
    i get a dark grey screen which says “Geeklet Settings”
    but no way to enter info.

    • sparky says:

      RTFM

    • M says:

      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.

    • Brandon says:

      Drag the shell to the desktop or else you have nothing to display the command output to.

  10. CuZt says:

    Very cool and super handy tool mate, thanks so much for the quick tutorial about it

  11. xavier says:

    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.

    • Dean says:

      Because reading a 50 line script is hard?

      • Brandon says:

        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.

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site