SSH Port Forwarding Utility Script for Secured Endpoint Testing

Wrote this quick little diddy for testing endpoints with SOAP UI that are traditionally not reachable unless on a specific box that has an IP range or network that is whitelisted for connection.

Read comments below and change as needed for your respective endpoint.

Be sure to terminate the script afterwards so that the tunnel is closed.

#Change IP to AWS Server IP and Correct Username
AWS_SERVER_IP="192.168.1.1"
AWS_SERVER_PORT="22"
AWS_SERVER_USER="myCoolUser"

#External app address that can only be hit from the EC2 Instance or Server.
#This is useful for debugging of Web Service Endpoints and Connectivity Tests.

EXTERNAL_APP_IP="appHostnameThatCanOnlyBeHitFromAwsBox.com"
EXTERNAL_APP_PORT="443"

#Local Port that you will hit to test appHostnameThatCanOnlyBeHitFromAwsBox
#aka open Web Browser and go to https://localhost:1337 and this will forward 
#the connection to appHostnameThatCanOnlyBeHitFromAwsBox and the respective port

LOCAL_APP_PORT="1337"

#Set the proper unix style path using either Cygdrive or Git-Bash

PLINK_PATH="/c/path/PLINK.exe"
PPK_PATH="/c/path/pathToPpk.ppk"

#PLINK Syntax: 
#Password: -pw password 
#Private Key: -i "$PPK_PATH"
#Run in Background: & at the end

"$PLINK_PATH" -N -L $LOCAL_APP_PORT:$EXTERNAL_APP_IP:$EXTERNAL_APP_PORT -ssh $AWS_SERVER_USER@$AWS_SERVER_IP -P $AWS_SERVER_PORT -i "$PPK_PATH" 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s