dotfiles

ref: 0662472a3009f9a00e0f4efdbf54f5a3b9ad516c

bin/is-vpn-connected


#!/usr/bin/env python

# Status code:
#
#   0 => Connected
#   1 => Not connected

import subprocess

cmd = 'nmcli --terse connection show --active'

def main():
    out = subprocess.check_output(cmd.split(' '))
    for line in out.splitlines():
        if 'vpn' in str(line):
            print('{"text": "VPN: up"}')
            return

    print('{"text": "VPN: down"}')


main()