/ scripts / network_vpn.sh
network_vpn.sh
 1  #!/usr/bin/env bash
 2  # setting the locale, some users have issues with different locales, this forces the correct one
 3  export LC_ALL=en_US.UTF-8
 4  
 5  current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
 6  source $current_dir/utils.sh
 7  
 8  vpn_function() {
 9    case $(uname -s) in
10    Linux)
11      #Show IP of tun0 if connected
12      vpn=$(ip -o -4 addr show dev tun0 | awk '{print $4}' | cut -d/ -f1)
13  
14      if [[ $vpn =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
15        echo $vpn
16      else
17        echo "NO VPN"
18      fi
19    ;;
20    
21    Darwin)
22      vpn=$(scutil --nc list | grep Connected)
23  
24      if [ -z $vpn ]; then
25        echo ""
26      else
27        echo "VPN"
28      fi
29      ;;
30  
31    CYGWIN* | MINGW32* | MSYS* | MINGW*)
32      # TODO - windows compatability
33      ;;
34    esac
35  }
36  
37  main() {
38  
39    echo $(vpn_function)
40  }
41  
42  # run main driver
43  main