Show What Apps & Processes Are Using an Internet Connection via Command Line

Apr 29, 2011 - 3 Comments

Much like you can monitor Mac OS X filesystem usage through the command line, you can also discover what apps are currently using your internet connection.

Here are two ways to do this, the first provides easy to read output and will print names of applications and processes that are connecting to the outside world:

lsof -nPi | cut -f 1 -d " "| uniq | tail -n +2

Running this command will give you something like:

SystemUIS
Dropbox
iChatAgen
Finder
iTunes
Google
ssh

Obviously these are just the application names and there isn’t much more data here, but if you’re just trying to track down a rogue bandwidth hogging app it’s sometimes adequate.

If you want more detailed information, we can revise the above command so that we get more raw data out of lsof by removing the pipes to other command line utilities, leaving us with unrefined details directly from lsof. You’ll also notice I cut out the -n flag because I want to see the host names this time around:

lsof -Pi

This will provide much more data, including the app name, PID, protocol, IP address, hostname, and the current status of the connection. All very helpful data.

If that is information overload, try piping the command through ‘more’ so it is easier to read in chunks, or use grep to sort data for a specific app or process, like so:

$ lsof -Pi |grep iChatAgen
iChatAgen 228 David 10u IPv4 0x0bfe44ec 0t0 UDP 127.0.0.1:5191->bos-d25v-r2d2.blue.aol.com:5191
iChatAgen 228 David 13u IPv4 0x1e148b1e 0t0 TCP 192.168.1.29:50051->206.198.4.49:5190 (ESTABLISHED)

lsof is a powerful utility with a myriad of uses. I covered using lsof to track down bandwidth issues quite some time ago, but it was using just the -i flag.

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, Tips & Tricks

3 Comments

» Comments RSS Feed

  1. sault says:

    Nice article.

  2. Ian says:

    You can also use netstat to see all open connections from all IP’s and ports to all other IP’s and ports

    Try this:

    netstat | grep -i stab

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

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