Created
June 24, 2024 20:03
-
-
Save Kline-/703a6359a0d26e8babb487379a18a878 to your computer and use it in GitHub Desktop.
A wrapper for the wireguard command to display the hostname of endpoints from local DNS.
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 | |
WG=/usr/bin/wg | |
OUTPUT=$(script --flush --quiet /dev/null --command $WG) | |
if [[ $# -gt 0 ]]; then | |
$WG $@ | |
exit | |
fi | |
if [[ ! -z $OUTPUT ]]; then | |
while read LINE; do | |
if [[ $LINE =~ ^.*(peer|interface) ]]; then | |
echo "$LINE" | |
elif [[ $LINE =~ ^.*allowed.* ]]; then | |
IPV4=$(printf "%q" "$LINE" | cut -d' ' -f3 | cut -d/ -f1 | cut -d\\ -f1) | |
HOST=$(host "$IPV4" | cut -d' ' -f5 | cut -d. -f1) | |
echo " $LINE" | |
echo " friendly name: $HOST" | |
else | |
echo " $LINE" | |
fi | |
done <<< "$OUTPUT" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment