List all Open Internet Connections on a Mac from Terminal to Track Down Bandwidth Issues

Sep 29, 2009 - 5 Comments

Terminal in OS X Recently the LAN at my office had been running slower than usual, and I couldn’t pinpoint what was using up all the extra bandwidth. I had a suspicion that P2P traffic was to blame but I just couldn’t see anything obvious on the offending machine. So the question of course, is how do you see what processes are connecting to the internet or the outside world from Mac OS X?

Using the lsof command line tool, we can pass the -i argument to list only the active and open internet connections on our Macs, and we can find out if there’s anything peculiar (or in my case, something hidden) going on and connecting to an outside address, and, this command will also show you what the process ID is of the offending application or task, so that we can kill it and stop the activity if desired.

Display a List of All Open Internet Connections in OS X from the Command Line

This must be entered from the Terminal of OS X, but it can be used remotely with SSH or locally on a Mac.

I logged into the offending Mac and typed the following command:

lsof -i

You shouldn’t need to use sudo but you can if desired or required for your specific use case.

Output of lsof is a little busy but if you’re familiar with the command line it shouldn’t be anything too crazy looking.

Here’s an example of the output displayed by this lsof -i command string:

MacMini:~ macuser$ lsof -i
SystemUIS 93 macuser 6u IPv4 0x04db27bc 0t0 UDP *:*
SystemUIS 93 macuser 10u IPv4 0x04db26e0 0t0 UDP *:*
iChatAgen 111 macuser 6u IPv4 0x07084734 0t0 UDP localhost:49490->localhost:49490
iChatAgen 111 macuser 10u IPv4 0x05666f28 0t0 TCP> (ESTABLISHED)
synergys 129 macuser 5u IPv4 0x05f2f6b0 0t0 TCP *:24800 (LISTEN)
Safari 148 macuser 10u IPv4 0x06db46e0 0t0 TCP> (CLOSE_WAIT)
iTunes 644 macuser 21u IPv4 0x05f2f2a4 0t0 TCP *:daap (LISTEN)

terminal-icon-512x5122 In the above lsof output display there’s nothing unusual, but in my aforementioned network troubleshooting, I discovered a BitTorrent client running hidden in the background of one of my networks Macs, and it was seeding several large files! Naturally I killed the BitTorrent client, removed the application, deleted the files, and the Mac LAN is running at full speed again.

Listing Only Established Internet Connections

If you happen to want to only display the established connections (meaning they are actively communicating and a link has been established between the local machine and an outside IP), you can use this command variation of the aforementioned lsof string:

lsof -i | grep -E "(LISTEN|ESTABLISHED)"

You can combine this with ‘watch’ to get an automatically updated list of established connections too.

And if you happen to know the process name, you can always use grep for that specific or vague name too.

This is a bit advanced, but it works quite well for Mac users who are comfortable with the terminal and command line in general. More novice Mac users can use Private Eye to monitor internet and network connections in OS X, which is a free but excellent third party application that runs in the graphical user interface and is a bit easier to parse, particularly if you’re not experienced with the terminal.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: David Mendez in Command Line, How to, Tips & Tricks, Troubleshooting, Utilities


» Comments RSS Feed

  1. tertiumsquid says:

    Can I assume the perpetrator was disciplined for unauthorized use of company computers (if he/she was caught)?

  2. M25 says:

    Awwww, come on… torrent-ing the box office weekend movie isn’t worth the bandwidth speed? Hahaha…

    Seriously though, thanks for the tip. thats a really useful command line to know.

  3. […] want to stop the agent running. You probably noticed the agent using something like LittleSnitch or lsof when it tries to access an outside server (typically Akamai) when it checks for software updates. […]

  4. […] using a free command line utility called 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 […]

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

Leave a Reply


Shop for Apple & Mac Deals on

Subscribe to OSXDaily

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