Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # This script provides a simple API to control VPN connections in macOS.
- DEFAULT_VPN="$(scutil --nc list | awk '/IPSec/ {print $5}' | sed 's/\"//g')"
- COMMAND=$1
- VPN_NAME=${2:-${DEFAULT_VPN}}
- function turn_on_vpn() {
- echo $(scutil --nc start ${VPN_NAME})
- get_vpn_status
- }
- function turn_off_vpn() {
- echo $(scutil --nc stop "${VPN_NAME}")
- get_vpn_status
- }
- function get_vpn_status() {
- echo "${VPN_NAME}: $(scutil --nc status "${VPN_NAME}" | sed -n 1p)";
- }
- function list_vpn_services() {
- echo "$(scutil --nc list | awk '/IPSec/ {print $5}' | sed 's/\"//g')"
- }
- case ${COMMAND} in
- up)
- turn_on_vpn
- ;;
- down)
- turn_off_vpn
- ;;
- status)
- get_vpn_status
- ;;
- list)
- list_vpn_services
- ;;
- *)
- echo "usage: vpn <command> [VPN Name]"
- echo ""
- echo "These are the VPN commands available:"
- echo ""
- echo " up Bring up the VPN connection"
- echo " down Stop the VPN connection"
- echo " status Get the VPN connection status"
- echo " list List VPN services configured"
- echo ""
- echo "Available VPNs:"
- echo ""
- echo "$(list_vpn_services)"
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement