-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh-proxy
64 lines (59 loc) · 1.83 KB
/
ssh-proxy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/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] <http-proxy> <proxy-port> <host> <port>
# with optional args:
# [-n <netcat>] - version or path to netcat/direct-connect program
# [-t <tunnel>] - version or path of http-tunnel program
# [-w <timout>] - 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 <netcat> and/or -t <tunnel>
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
##