Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to automate the process of connecting to a Windows machine via RDP and then initiating an ssh tunnel back to the client machine.

The way I currently manually handle this:

  1. I log into the RDP server and run the following command to aid in helping me find the right IP address:

    netstat -a | find "3389" | find "ESTABLISHED"

    This spits out a line that contains the connection details for my computer's rdp connection. This IP is the IP that the server will be able to route through back to my computer.

  2. I manually open PuTTY and open an existing session that's properly configured with username and key, change the IP appropriately, and click connect.

At this point on my client machine I can now access some resources via the ssh port forwarding.

What I would like to do is figure out some way to automate this. The Microsoft remote desktop client has the ability to launch an program upon connection. What I don't know is what program or combination of programs to run.

share|improve this question

1 Answer 1

Plink is a command line connection helper for Putty. Using Plink you can avoid the manual operations that you are performing in step 2

I manually open PuTTY and open an existing session that's properly configured with username and key, change the IP appropriately, and click connect.

For the arguments to Plink I'd suggest further piping the IP address you correctly obtained using netstat and find.

So in the end the command might look like

netstat -a | find "3389" | find "ESTABLISHED" > | plink -ssh

Remember to establish that plink is supposed to use SSH like in the above command, or better still set the windows environment variable PLINK_PROTOCOL to ssh.

Also ensure that the plink executable file's path is established in the PATH environment variable.

share|improve this answer
    
The netstat line doesn't result in just a single IP, only one line out netstat output. –  mindless.panda Feb 7 '12 at 0:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.