01-23-07 12:31 PM
Hi there,
I would like to display all local ports that have been forwarded using ssh
(so they can be displayed on a desktop widget).
ssh port forwards are commands that always start with either "ssh -L"
or "sudo ssh -L". Here's an example:
sudo ssh -L 80:192.168.127.2:80 -L 2060:192.168.127.124:5900 -p
65456 -i /home/allistar/.ssh/id_rsa allistar@somehost.com cat -
The above command represents two forwarded ports.
I would like to extract out of that this:
80:192.168.127.2:80
2060:192.168.127.124:5900
The below script works fine, but I'm hoping there's a better way of
achieving this.
ps -eo "args" | egrep "^ssh -L|^sudo ssh -L" | sed "s/-L /\n-L \n/g" |
egrep -A 1 "\-L" | egrep -v "^\-" | sed -e 's/ .*//' -e '/^$/d'
Does anyone have any better suggestions that the above script?
Ideally (but not essential) I'd like to associate each forwarded port to the
host that is being connected too.
Thanks,
Allistar.
[ Post a follow-up to this message ]
|