Skip to content

Instantly share code, notes, and snippets.

@loosebits
Last active August 29, 2015 14:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loosebits/9418c55119a537f0ab66 to your computer and use it in GitHub Desktop.
Save loosebits/9418c55119a537f0ab66 to your computer and use it in GitHub Desktop.
VPN/Routing script
#! /bin/bash
PPPOE=HCSC
IFNAME=utun0
SUBNET="10.0.0.0/8"
if [ $(id -u) != "0" ]
then
echo "Running using sudo.."
sudo "$0" "$@"
exit $?
fi
GATEWAY="$(route -n get 8.8.8.8 | grep gateway | awk '{print $2}')"
echo "Detected gateway to be $GATEWAY"
scutil --nc start $PPPOE
while ! ifconfig | grep $IFNAME > /dev/null; do
sleep .2
done
sleep 1
route change default $GATEWAY
route add -net $SUBNET `ifconfig $IFNAME | grep inet | awk '{print $2}'`
@loosebits
Copy link
Author

Grabs the default route, connects to the VPN, waits for the connection and then splits the routing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment