juretta.com

iTunes: Who's connected

July 11, 2005
Tags: Dropbox iTunes Mac

Ever wondering who those "n users connected" are when you look at the Sharing part of the Preferences of your iTunes? Well wonder no more - it turns out fairly easy to figure out in Terminal.app; just type this line:

lsof -r 2 -n -P -F n -c iTunes -a -i TCP@`hostname`:3689

and it will tell you the IP address of each connection, together with the music file the connection is listening to. lsof is a UNIX tool which is capable of listing the files a particular process opens - including even the files being accessed from remote connections, such as NFS, and iTunes in our case. Some short explanations of the parameters used:

  • -r 2: list the opened files repeatedly, and refresh the list every 2 seconds.
  • -n: show numeric IP address instead of domain names.
  • -P: show port info in numbers instead of names (e.g., 3689 vs. `daap').
  • -F n: display field `name' (n).
  • -c iTunes: only list files opened by process with name 'iTunes'.
  • -a: logical `and' to connect more than one conditions.
  • -i TCP@`hostname`:3689: only list files involving the specified address; in this case the protocol must be TCP, connecting to my machine, and connecting to port 3689.

About

This is the defunct blog of Stefan Saasen.