How can I programmatically detect the presence of a VPN?
That's exactly what I have in my own code. In bash it looks like:

vpn=$( netstat -rn | grep utun1 | wc -l )
if [[ $vpn -eq 0 ]] ; then
    # no VPN active
else
    # VPN active
fi


It's been pretty reliable in my environment. I'd like to be able to discern different VPN configurations in effect, but not so much as to have to code it (yet).