From f9ea808cb6f422603efbdc11ef16af156159fdfb Mon Sep 17 00:00:00 2001 From: Vincent Composieux Date: Fri, 1 Jun 2018 15:28:55 +0200 Subject: [PATCH] Added sshproxy and stopsshproxy functions --- .functions | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/.functions b/.functions index 6d9c653..1ad781a 100644 --- a/.functions +++ b/.functions @@ -167,8 +167,8 @@ function lighthouse { fi } -# Sets Cloudflare DNS servers on a network interface -function opendns() { +# Asks the user to select a network interface and returns the result +function selectnetworkinterface() { echo "Select the network interface:\n1) Belkin USB-C LAN\n2) Wi-Fi" read n @@ -178,10 +178,41 @@ function opendns() { *) echo "Invalid option"; return;; esac + return $selected +} + +# Sets Cloudflare DNS servers on a network interface +function opendns() { + selectnetworkinterface + echo "\n-> Setting open DNS servers on network interface '$selected'" networksetup -setdnsservers $selected 1.1.1.1 1.0.0.1 } +# Sets SSH proxy on a network interface +# Usage: sshproxy @ +function sshproxy() { + selectnetworkinterface + + echo "\n-> Setting socks proxy on network interface '$selected'" + + ssh -fN -D 5000 $1 + networksetup -setsocksfirewallproxy $selected localhost 5000 + + echo "\n-> All set, proxy is ready" +} + +# Sets SSH proxy on a network interface +# Usage: stopsshproxy +function stopsshproxy() { + selectnetworkinterface + + echo "\n-> Setting socks proxy on network interface '$selected'" + + networksetup -setsocksfirewallproxystate $selected off + ps x | grep "[s]sh -fN -D 5000" | awk '{print $1}' | xargs kill -9 +} + # Automatically Starting tmux on SSH function ssht() { SSH_HOST="${@: -1}"