Redcap was written because I need to track SSH remote forwards by their process id, and all I have is the port they’re forwarding to. You can’t pair the two together unless you have root access, though – and that’s where Redcap comes in. You run Redcap as root, and then you can ask it to do the pairing for you.
gem install redcap
As a server, you’ll also want EventMachine installed:
gem install eventmachine
And then, the service must be run as root (so it can get all the requierd port and process information):
$ sudo redcap
And in code, as a client:
require 'rubygems'
require 'redcap'
Redcap.pid_for_port(10342) #=> 26151
Pat Allan wrote this code in May 2011, but all the hard work for daemonising the process, logging, and a pid file was done in a gist by James Healy.
Released under the MIT Licence. Fork, contribute, re-use, whatever.