Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # This script provides a simple API to control VPN connections in macOS.
  4.  
  5. DEFAULT_VPN="$(scutil --nc list | awk '/IPSec/ {print $5}' | sed 's/\"//g')"
  6. COMMAND=$1
  7. VPN_NAME=${2:-${DEFAULT_VPN}}
  8.  
  9. function turn_on_vpn() {
  10. echo $(scutil --nc start ${VPN_NAME})
  11. get_vpn_status
  12. }
  13.  
  14. function turn_off_vpn() {
  15. echo $(scutil --nc stop "${VPN_NAME}")
  16. get_vpn_status
  17. }
  18.  
  19. function get_vpn_status() {
  20. echo "${VPN_NAME}: $(scutil --nc status "${VPN_NAME}" | sed -n 1p)";
  21. }
  22.  
  23. function list_vpn_services() {
  24. echo "$(scutil --nc list | awk '/IPSec/ {print $5}' | sed 's/\"//g')"
  25. }
  26.  
  27. case ${COMMAND} in
  28.  
  29. up)
  30. turn_on_vpn
  31. ;;
  32.  
  33. down)
  34. turn_off_vpn
  35. ;;
  36.  
  37. status)
  38. get_vpn_status
  39. ;;
  40.  
  41. list)
  42. list_vpn_services
  43. ;;
  44.  
  45. *)
  46. echo "usage: vpn <command> [VPN Name]"
  47. echo ""
  48. echo "These are the VPN commands available:"
  49. echo ""
  50. echo " up Bring up the VPN connection"
  51. echo " down Stop the VPN connection"
  52. echo " status Get the VPN connection status"
  53. echo " list List VPN services configured"
  54. echo ""
  55. echo "Available VPNs:"
  56. echo ""
  57. echo "$(list_vpn_services)"
  58. ;;
  59. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement