6

I would like to get the VPN connection status in a script.

On macOS 13.2.1 I have two VPNs configured (i believe both are of type IKEv2) but i can see neither of them using

  • scutil --nc list nor
  • networksetup -listpppoeservices.

Is there another way to query the status of these VPNs?

2
  • A VPN will create or use an existing virtual interface (i.e. utunX)to route traffic through. Which interface does your VPN use?
    – Allan
    Commented Feb 23, 2023 at 14:26
  • networksetup -listpppoeservices used to work for me but it suddenly stopped listing my VPN configuration. I even recreated the VPN configuration under network settings but it's still not listed. I'm not sure if this is deliberate or a bug in macOS 13.2.1. Commented Mar 8, 2023 at 10:19

1 Answer 1

2

If you are speaking of a VPN used to access a private network, perhaps the easiest approach would be to check if an IP address specific to that network is reachable.

For example, if your VPN connects you to a network 192.168.100.0/24, using ping to check if 192.168.100.1 (probably the gateway) is reachable:

if ping -c 4 192.168.100.1 &> /dev/null
then
  echo "connected"
else
  echo "not connected"
fi

Solution copied from this answer (in my example, -c 4 tries 4 times).

If you are using a VPN to avoid blocking, you might instead test against any IP address that is otherwise blocked.

This approach is not very sophisticated, but its advantage is its simplicity, and that it should work independent from the type of VPN and also on most operating systems.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .