Skip to content

Instantly share code, notes, and snippets.

@dgoguerra
Forked from mnewt/proxy-toggle.sh
Last active August 6, 2024 00:10
Show Gist options
  • Select an option

  • Save dgoguerra/66d496345ee7e53169ad to your computer and use it in GitHub Desktop.

Select an option

Save dgoguerra/66d496345ee7e53169ad to your computer and use it in GitHub Desktop.

Revisions

  1. dgoguerra revised this gist Jan 18, 2016. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion proxy-toggle.sh
    Original file line number Diff line number Diff line change
    @@ -8,11 +8,12 @@ PROXY_PORT=1080
    # authentication.
    SOCKS_PROC_USER="username"
    SOCKS_PROC_HOST="example.com"
    SOCKS_PROC_IDENTITY="~/.ssh/id_rsa"

    SOCKS_PROC_LOG=/tmp/ssh-socks-proxy-log.txt
    SOCKS_PROC_PIDFILE=/tmp/ssh-socks-proxy-pid.txt

    SOCKS_PROC_CMD="ssh -t -t -D $PROXY_HOST:$PROXY_PORT $SOCKS_PROC_USER@$SOCKS_PROC_HOST"
    SOCKS_PROC_CMD="ssh -i $SOCKS_PROC_IDENTITY -t -t -D $PROXY_HOST:$PROXY_PORT $SOCKS_PROC_USER@$SOCKS_PROC_HOST"

    if [[ $1 == "on" ]]; then
    nohup $SOCKS_PROC_CMD > "$SOCKS_PROC_LOG" 2>&1 &
  2. dgoguerra revised this gist Sep 25, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion proxy-toggle.sh
    Original file line number Diff line number Diff line change
    @@ -6,12 +6,13 @@ PROXY_PORT=1080

    # A host where ssh can login without interaction, with a key-based
    # authentication.
    SOCKS_PROC_USER="username"
    SOCKS_PROC_HOST="example.com"

    SOCKS_PROC_LOG=/tmp/ssh-socks-proxy-log.txt
    SOCKS_PROC_PIDFILE=/tmp/ssh-socks-proxy-pid.txt

    SOCKS_PROC_CMD="ssh -t -t -D $PROXY_HOST:$PROXY_PORT $SOCKS_PROC_HOST"
    SOCKS_PROC_CMD="ssh -t -t -D $PROXY_HOST:$PROXY_PORT $SOCKS_PROC_USER@$SOCKS_PROC_HOST"

    if [[ $1 == "on" ]]; then
    nohup $SOCKS_PROC_CMD > "$SOCKS_PROC_LOG" 2>&1 &
  3. dgoguerra revised this gist Sep 7, 2015. No changes.
  4. dgoguerra revised this gist Sep 7, 2015. 1 changed file with 17 additions and 2 deletions.
    19 changes: 17 additions & 2 deletions proxy-toggle.sh
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,29 @@
    #!/bin/sh

    PROXY_INTERFACE="USB Ethernet"
    PROXY_HOST=localhost
    PROXY_INTERFACE="Wi-Fi"
    PROXY_HOST=127.0.0.1
    PROXY_PORT=1080

    # A host where ssh can login without interaction, with a key-based
    # authentication.
    SOCKS_PROC_HOST="example.com"

    SOCKS_PROC_LOG=/tmp/ssh-socks-proxy-log.txt
    SOCKS_PROC_PIDFILE=/tmp/ssh-socks-proxy-pid.txt

    SOCKS_PROC_CMD="ssh -t -t -D $PROXY_HOST:$PROXY_PORT $SOCKS_PROC_HOST"

    if [[ $1 == "on" ]]; then
    nohup $SOCKS_PROC_CMD > "$SOCKS_PROC_LOG" 2>&1 &
    echo $! > "$SOCKS_PROC_PIDFILE"

    sudo networksetup -setsocksfirewallproxy "$PROXY_INTERFACE" $PROXY_HOST $PROXY_PORT
    echo "SOCKS proxy enabled"

    elif [[ $1 == "off" ]]; then
    sudo kill -9 $(cat "$SOCKS_PROC_PIDFILE")
    rm "$SOCKS_PROC_PIDFILE"

    sudo networksetup -setsocksfirewallproxystate "$PROXY_INTERFACE" off
    echo "SOCKS proxy disabled"

  5. @mnewt mnewt revised this gist Sep 13, 2012. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion proxy-toggle.sh
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,6 @@ elif [[ $1 == "status" ]]; then
    echo

    else
    echo $1
    echo "`basename $0` toggles SOCKS proxy settings on OS X"
    echo
    echo "Usage: "
  6. @mnewt mnewt revised this gist Sep 13, 2012. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions proxy-toggle.sh
    Original file line number Diff line number Diff line change
    @@ -12,13 +12,26 @@ elif [[ $1 == "off" ]]; then
    sudo networksetup -setsocksfirewallproxystate "$PROXY_INTERFACE" off
    echo "SOCKS proxy disabled"

    elif [[ $1 == "status" ]]; then
    echo "======================================================"
    echo "Network Services:"
    echo "======================================================"
    networksetup -listallnetworkservices
    echo
    echo "======================================================"
    echo "Current SOCKS Proxy Settings:"
    echo "======================================================"
    networksetup -getsocksfirewallproxy "$PROXY_INTERFACE"
    echo

    else
    echo $1
    echo "`basename $0` toggles SOCKS proxy settings on OS X"
    echo
    echo "Usage: "
    echo " $ proxy on # turns SOCKS proxy on"
    echo " $ proxy off # turns SOCKS proxy off"
    echo " $ proxy status # prints status of proxy settings"
    echo
    echo "proxy interface: " $PROXY_INTERFACE
    echo "proxy host: " $PROXY_HOST
  7. @mnewt mnewt renamed this gist Sep 13, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. @mnewt mnewt created this gist Sep 13, 2012.
    28 changes: 28 additions & 0 deletions proxy-toggle
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/bin/sh

    PROXY_INTERFACE="USB Ethernet"
    PROXY_HOST=localhost
    PROXY_PORT=1080

    if [[ $1 == "on" ]]; then
    sudo networksetup -setsocksfirewallproxy "$PROXY_INTERFACE" $PROXY_HOST $PROXY_PORT
    echo "SOCKS proxy enabled"

    elif [[ $1 == "off" ]]; then
    sudo networksetup -setsocksfirewallproxystate "$PROXY_INTERFACE" off
    echo "SOCKS proxy disabled"

    else
    echo $1
    echo "`basename $0` toggles SOCKS proxy settings on OS X"
    echo
    echo "Usage: "
    echo " $ proxy on # turns SOCKS proxy on"
    echo " $ proxy off # turns SOCKS proxy off"
    echo
    echo "proxy interface: " $PROXY_INTERFACE
    echo "proxy host: " $PROXY_HOST
    echo "proxy port: " $PROXY_PORT
    echo
    exit 65 # end process with error to indicate incorrect arguments
    fi