Created
September 5, 2021 21:00
-
-
Save cboddy/2ca01449a5a038ea198b2e065b208c59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu -o pipefail | |
# Check if your external IP address is in an Openvpn client | |
# config file. | |
# | |
# | |
# Usage: ./is_connected_via_openvpn.sh [openvpn-vpn-config-path] | |
# Defaults to checking /etc/openvpn/*.conf | |
# | |
# | |
# Gets external IP address with curl from api.ipify.org | |
# Uses dig to query any DNS names in openvpn config files | |
# | |
# | |
openvpn_configs_path="${1:-/etc/openvpn/*.conf}" | |
is_connected_via_openvpn() { | |
proton_ips=$(awk '/remote / {print $2}' $openvpn_configs_path | sort -u | xargs dig +short) | |
my_ip=$(curl -s https://api.ipify.org) | |
if grep $my_ip <<< $(echo $proton_ips) >/dev/null; | |
then | |
echo "Is using openvpn" | |
return 0 | |
else | |
echo "Not using openvpn" | |
return 1 | |
fi | |
} | |
is_connected_via_openvpn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment