Skip to content

Instantly share code, notes, and snippets.

@whoamiTM
Last active August 7, 2018 03:21
Show Gist options
  • Save whoamiTM/263cb87502e4b91abe91be595f86ee0a to your computer and use it in GitHub Desktop.
Save whoamiTM/263cb87502e4b91abe91be595f86ee0a to your computer and use it in GitHub Desktop.
VPN Kill Switch For MacOS |Terminal User Interface | Route(8)
#! /bin/bash
echo off
defgw=$(route get 0.0.0.0 2>/dev/null | awk '/gateway: / {print $2}';)
def_int=$(route get 0.0.0.0 2>/dev/null | awk '/interface: / {print $2}';)
clear
:start
clear
echo Simple VPN KillSwitch, ver. 1.1 - by whoami
echo
echo Your default gateway is "$defgw" on interface "$def_int"
echo "-if nothing appears or its incorrect, add it manually (Press "4")"
echo
echo USAGE:
echo
PS3='Please enter your choice: '
options=("Manually insert VPN IP" "Enable Kill Switch (IP "$defgw")" "Disable Kill Switch (IP "$defgw")" "Manually set default gateway if its not detected above." "Exit Kill Switch")
select opt in "${options[@]}"
do
case $opt in
"Manually insert VPN IP")
echo -n "Enter you VPN IP and press [ENTER]: "
read vpn
echo VPN $vpn Configured...
sleep 2
;;
"Enable Kill Switch (IP "$defgw")")
sudo route -n add $vpn $defgw 255.255.255.255 -static
sudo route -n delete default default -ifp $def_int -ifa 192.168.0.24
echo Kill Switch Enabled...
sleep 1
;;
"Disable Kill Switch (IP "$defgw")")
sudo route -n delete $vpn $defgw 255.255.255.255 -static
sudo route -n add default $defgw default -ifp $def_int -ifa 192.168.0.24
echo Kill Switch Disabled...
sleep 1
;;
"Manually set default gateway if its not detected above.")
echo -n "Enter Default Gateway IP and press [ENTER]: "
read defgw
echo Default Gateway $defgw Configured...
;;
"Exit Kill Switch")
break
;;
*) echo "invalid option $REPLY";;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment