Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .