Geek Posted April 29, 2011 Posted April 29, 2011 <div class="KonaBody"><p>Much like you can <a href="http://osxdaily.com/2011/04/22/monitor-mac-os-x-filesystem-usage-access-with-opensnoop/">monitor Mac OS X filesystem usage</a> through the <a href="http://osxdaily.com/category/command-line/">command line</a>, you can also discover what apps are currently using your internet connection.</p> <p>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:</p> <p><code>lsof -nPi | cut -f 1 -d " "| uniq | tail -n +2</code></p> <p>Running this command will give you something like:</p> <p><code>SystemUIS Dropbox iChatAgen Finder iTunes Google ssh</code></p> <p>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. </p> <p>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:</p> <p><code>lsof -Pi</code></p> <p>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. </p> <p>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:</p> <p><code>$ 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)</code></p> <p>lsof is a powerful utility with a myriad of uses. I covered <a href="http://osxdaily.com/2009/09/29/list-all-open-internet-connections-on-a-mac-to-track-down-bandwidth-issues/">using lsof to track down bandwidth issues</a> quite some time ago, but it was using just the -i flag.</p> </div> <p><a href="http://feedads.g.doubleclick.net/~a/d74sr5W35fSsz8v-mgyZHw_mOn8/0/da"><img src="http://feedads.g.doubleclick.net/~a/d74sr5W35fSsz8v-mgyZHw_mOn8/0/di" border="0" ismap="true"></img></a><br/> <a href="http://feedads.g.doubleclick.net/~a/d74sr5W35fSsz8v-mgyZHw_mOn8/1/da"><img src="http://feedads.g.doubleclick.net/~a/d74sr5W35fSsz8v-mgyZHw_mOn8/1/di" border="0" ismap="true"></img></a></p><div class="feedflare"> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=rM5SutEoTzU:3v31lJzJo1c:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=rM5SutEoTzU:3v31lJzJo1c:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/osxdaily?i=rM5SutEoTzU:3v31lJzJo1c:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=rM5SutEoTzU:3v31lJzJo1c:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/osxdaily?i=rM5SutEoTzU:3v31lJzJo1c:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=rM5SutEoTzU:3v31lJzJo1c:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=rM5SutEoTzU:3v31lJzJo1c:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=qj6IDK7rITs" border="0"></img></a> </div><img src="http://feeds.feedburner.com/~r/osxdaily/~4/rM5SutEoTzU" height="1" width="1"/> View the full article
Recommended Posts