Skip to content

Instantly share code, notes, and snippets.

@Kline-
Created June 24, 2024 20:03
Show Gist options
  • Save Kline-/703a6359a0d26e8babb487379a18a878 to your computer and use it in GitHub Desktop.
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.
#!/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