#!/bin/bash # # Simple shell wrapper to proxy ssh appropriately when only SOMETIMES # behind a draconian firewall. Indended for use inside an ssh-config # file, something like this: # # Host * # ProxyCommand $HOME/.ssh/proxy httpproxy.foo.com 8080 %h %p # # Generally, the usage of this is: # proxy [optional-args] # with optional args: # [-n ] - version or path to netcat/direct-connect program # [-t ] - version or path of http-tunnel program # [-w ] - timeout (seconds) to test connection to proxy server # # This script assumes both netcat (nc) and corkscrew (an http-proxy # available from http://www.agroman.net/corkscrew). Netcat is used # both to detect the availablility of the destination or proxy hosts # as well as for direct connections. Both are assumed to be resident # in your PATH. If not, you may specify a different http-proxy or # alternate location for netcat on the command line (in your ssh # config) OR, of course, "use the source, Luke"... # # Author: Eric Engstrom (engstrom(-AT-)m t u(-DOT-)n e t) # # $Id: ssh-proxy,v 1.6 2004-08-11 16:50:55 eric Exp $ ## # set to "echo" to debug DEBUG= # defaults tunnel=corkscrew netcat=nc timeout=8 # if "nc" not found, try "netcat" if ! type -p ${netcat} >/dev/null 2>&1; then netcat="netcat" fi if ! type -p ${netcat} >/dev/null 2>&1; then echo "Cannot find netcat - failing..." 1>&2 exit 1; fi # parse args - can specify -n and/or -t while getopts "n:t:w:" OPT; do #echo "$OPT $OPTARG $OPTIND" case $OPT in n) netcat=$OPTARG ;; t) tunnel=$OPTARG ;; w) timeout=$OPTARG ;; esac done shift $(($OPTIND - 1)) # test connection to proxy, then tunnel or not if ${netcat} -w ${timeout} -z $3 $4 >/dev/null 2>&1; then $DEBUG exec ${netcat} $3 $4 else $DEBUG exec ${tunnel} $* fi ##