Skip to content

Instantly share code, notes, and snippets.

@cyyself
Last active January 30, 2025 14:49
Show Gist options
  • Save cyyself/90047489a6b51ec36cba3a4066b90782 to your computer and use it in GitHub Desktop.
Save cyyself/90047489a6b51ec36cba3a4066b90782 to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
wg_filter="wg0 wg1" # EDITME
current_time=$(date +%s)
wg show all dump | awk '{if ($5 != "off") print $1,$6}' | while read -r each_dump; do
interface=$(echo $each_dump | cut -d' ' -f1)
last_handshake=$(echo $each_dump | cut -d' ' -f2)
if echo $wg_filter | grep -q $interface; then
if [ $((current_time - last_handshake)) -gt 240 ]; then
wg set $interface listen-port 0
fi
fi
done < <(wg show all dump | awk '{if ($5 != "off") print $1,$6}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment