Netstat and PIDs

Posted:
in Genius Bar edited January 2014
OK, I'm looking for a way to link a connection (that shows up in netstat) to its parent PID. I'm just starting to get involved with all this Unix stuff... so go easy on me.



I've looked thoroughly through the netstat man page, and nada. However, a quick google for 'pid netstat' shows a netstat version (8) that does this with a -p flag. Is there any way I can install that on my mac as an auxiliary command?



I also tried searching fink, and nada.



I thought I would try the SourceForge page, and searched for netstat there. I came up with this: Nnetstat .1Alpha it shows a gui on the screenshot, but when you click the download link, it shows a shell-script-like file. It apparently is able to reference the PID. Any guesses on how to get this thing to work?



[ Edit: err, I guess it is a gui program for gnome(?). Anyways, is it still possible to rip some command out of it? I tried sorting through it with my limited *nix scripting knowledge, and it looks like it just reads some output files that don't seem to exist on OS X... at least there isn't a /proc/ directory, and I couldn't locate a 'tcp' text file.]



Just to give you an idea of where I'm going with this, here's my thought: I've recently discovered lsof, which can list open files and the process that has them open. By piping that into grep for the directory of my music, I can see what music files are being listened to. Since I am on a University campus, and there are often people accessing my music through CIFS and iTunes, I thought it would be cool to (learn to) write a shell script that will show WHO is listening to WHAT music. I know CIFS accesses different users through different PIDs (I haven't toyed with iTunes enough yet to figure it out -- I hope it does it by different PID, too, but I somehow doubt it... I may have to glob together all the iTunes sharing, which wouldn't be that big a deal... there aren't too many of us Mac users on campus), so by connecting the hostname and PID, and the PID to the file, I can show which machines are listening to which music file. Whew. I hope I got that all right.



Any comments/suggestions on what I've done and my ideas? Any other ideas?

Comments

  • Reply 1 of 4
    1337_5l4xx0r1337_5l4xx0r Posts: 1,558member
    You're mad.



    But yeah, if you get your hands on a netstat that lists PIDS, we can help you write a script.



    Is this post helpful? Hmmm....
  • Reply 2 of 4
    baumanbauman Posts: 1,248member
    Hmm.. Fine line between genius and insanity there is. I'm afraid this project is teetering towards the latter



    Still, does anyone know of a command that lists connections with their associated PID?
  • Reply 3 of 4
    baumanbauman Posts: 1,248member
    (Shameless bump)



    Soooo, anyone? How about a more explicitly *nix forum where there would be helpful, friendly people? I've tried googling, but with absolutely no success.



    I think it would be über-133t... if I could get this working
  • Reply 4 of 4
    dobbydobby Posts: 797member
    Try the osx admin mailing list at www.omnigroup.com



    Dobby.
Sign In or Register to comment.