Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

View open sockets in Transmission or other apps Network
I like the Torrent client Transmission, but right now it does not have the same level of detail as some other clients do (BitTorrent or Azureus) such as showing the IPs of the peers you are connected to. So I wrote a script, and I have GeekTool run it every five seconds and then I put the results in a window on my desktop. The result of the script is a list of open sockets, and a title at the top that tells me how many Transmission is using.

Here's the code:

#!/bin/sh
ThePID=`ps -U yourusernamehere | grep TRANSMISSION | grep -v grep | awk '{ print $1 }'`; 
TheFiles=`fstat -p $ThePID | grep stream | wc -l`; 
echo $TheFiles " Transmission files open"; 
echo; 
netstat -d -n -f inet | grep "ESTABLISHED" | grep -v 127 | awk '{print $5}'

Substitute your user name and the name of the application you want to monitor above, but it does need to be the name exactly as it appears in the ps command.

A brief explanation of what is going on here. The first part of the script determines the current PID of the Transmission client, but you could grep for any application name, such as a browser if you wanted to monitor its active connections.

The remaining lines use the PID of the application that comes back to narrow the search down to just the sockets that app is using, and also remove the local host connections and then print out the IPs and ports with a total.

Enjoy, feedback welcome.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[10,924 views]  

View open sockets in Transmission or other apps | 7 comments | Create New Account
Click here to return to the 'View open sockets in Transmission or other apps' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
View open sockets in Transmission or other apps
Authored by: mabino on Feb 16, '06 08:36:06AM

Add $USER to grab the current user's username.



[ Reply to This | # ]
View open sockets in Transmission or other apps
Authored by: genericuser on Feb 16, '06 10:33:20AM
StreamWatcher is an excellent graphical application that does something similar with a lot less hassle.

[ Reply to This | # ]
fstat?
Authored by: FireBreathingDog on Feb 16, '06 03:56:45PM

If 'fstat' part of the standard Darwin/OS X install? I don't seem to have it in my default path, and can't find it anywhere...



[ Reply to This | # ]
fstat?
Authored by: Intenzity on Feb 16, '06 11:40:55PM

It must be beause I do not have Fink/Darwin or any non-default install Unix binaries on my machine, just regular old 10.3.



[ Reply to This | # ]
fstat not in Tiger
Authored by: hayne on Feb 17, '06 10:12:44AM

I believe that 'fstat' was removed from the standard install in Tiger.
I doesn't exist on my 10.4.5 system

As has already been mentioned, the equivalent functionality is available via 'lsof'



[ Reply to This | # ]
View open sockets in Transmission or other apps
Authored by: mbartosh on Feb 17, '06 07:45:04AM

lsof -i

or, for system proceses, sudo lsof -i

---
4am Media, Inc. Mac OS X Training and Consulting



[ Reply to This | # ]
View open sockets in Transmission or other apps
Authored by: zs on Feb 20, '06 08:18:48AM
... grep -v 127 ... is a little too lazy. It will remove all IP addresses that have "127" in them but are not the localhost. Try: grep -v 127\.0\.0\.1

---
zs

[ Reply to This | # ]