I connect to a work
Virtual Private Network (VPN) from home using a
MacBook Pro
laptop running
OS X El
Capitan (10.11.6) and was curious if there was a way that I could determine
whether the system was connected to the VPN or disconnected from a VPN using a
command-line
interface (CLI), i.e., a
Terminal window, other than by checking the IP address that
external systems see for the system, e.g., by visiting
WhatIsMyIP.com. At
How can I tell if OS X is connected to a VPN network from the command line?,
I found someone suggesting using the
scutil command
scutil --nc list
and
piping
the output to the grep command looking for the word "Connected", i.e.,
scutil --nc list | grep Connected
. However, that didn't work
when I attempted to discern whether the laptop was connected to the VPN via
that method, since the scutil command always produced the following output
whether or not the system was connected to the VPN:
$ scutil --nc list Available network connection services in the current set (*=enabled): $
However, I was able to determine if the system was connected to the VPN by using the method listed in the post by the person who posed the question. I.e., I could use the ifconfig command and count the number of occurences of "utun0," since the count was zero if the system was not connected to the VPN and one if it was connected to the VPN. E.g., if the system was not connected to the VPN, I would see the following output.
$ ifconfig | grep utun0 $ ifconfig | grep -c utun0 0 $
When the system was connected to the VPN, I would see the following output:
$ ifconfig | grep utun0 utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1400 $ ifconfig | grep -c utun0 1 $
[ More Info ]