netstat -n to get the tcp channel and grep tcp/channel /proc/*/fd. I'm sure you can do the shell script around that.