Timac / VPNStatus

VPNStatus, a replacement for macOS builtin VPN Status
https://blog.timac.org/2018/0719-vpnstatus/
MIT License
221 stars 31 forks source link

Shut Off All VPNs with vpnutil #13

Open lukerbs opened 2 years ago

lukerbs commented 2 years ago

Hi,

Is there a way to shut off all VPNs with a single command using vpnutil?

Thanks

Timac commented 2 years ago

vpnutil can stop one single VPN with the command:

vpnutil stop MyVPN

It has no built-in command to stop all VPNs (could be an interesting new feature). However you could write a simple script using vpnutil to stop each VPN one by one. For example a bash script like:

#!/bin/bash

vpnutil stop MyVPN1
vpnutil stop MyVPN2
dronenb commented 7 months ago

@lukerbs you can use the following bash script using the new machine readable vpnutil list output (assumes you also have jq CLI installed):

#!/usr/bin/env bash

ORIG_IFS="${IFS}"
IFS=$'\n'
for vpn_name in $(vpnutil list  | jq -r '.VPNs[].name'); do
  vpnutil stop "${vpn_name}"
done
IFS="${ORIG_IFS}"