#!/bin/sh PROTO="SOCKS" HOST="" PORT="22" verb=false while getopts P:H:p:vh o do case "$o" in P) PROTO=$OPTARG;; H) HOST=$OPTARG;; p) PORT=$OPTARG;; v) verb=true;; h) echo "Usage: $0 [-P {HTTP|HTTPS|SOCKS}] -H [-p ]"; esac done function nullProxy { if [ "$verb" = "true" ]; then echo "No proxy configured connecting directly" > /dev/stderr fi exec netcat -c "$HOST" "$PORT" } # Go immediately to the NULL proxy if there's no proxy configured. PROXY_HOSTNAME=$(scutil --proxy | awk '$1 ~ /'"$PROTO"'Proxy/ { print $3 }') if [ "$PROXY_HOSTNAME" = "" ]; then nullProxy; fi PROXY_PORT=$(scutil --proxy | awk '$1 ~ /'"$PROTO"'Port/ { print $3 }') # Use the 'printf' command to force any escaped characters in the username # back to their original value (like the '\' in NTLM domain usernames) CONNECT_USER=$(printf $(security find-internet-password -s "$PROXY_HOSTNAME" 2>&1 \ | awk '$1 ~ /"acct"/ { print $2 }' \ | sed -Ee 's/^"(.*)"$/\1/') ) CONNECT_PASSWORD=$(security find-internet-password -g -s "$PROXY_HOSTNAME" 2>&1 \ | sed -nEe 's/password: "(.*)"$/\1/p') export CONNECT_USER CONNECT_PASSWORD if [ "$verb" = "true" ]; then echo "Using proxy configuration: $CONNECT_USER@$PROXY_HOSTNAME:$PROXY_PORT" > /dev/stderr fi exec /usr/local/bin/connect -R local -a name -4 \ -H "$PROXY_HOSTNAME:$PROXY_PORT" $HOST $PORT