Script to locate all ssh forwarded ports
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > Script to locate all ssh forwarded ports




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Script to locate all ssh forwarded ports  
Allistar


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:22 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register