Created
July 17, 2025 08:08
-
-
Save jensmeindertsma/080930c8f38479b0dfd207e134e3b473 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# Try to get IPv4 address and mask from tun0 | |
tun_info=$(ip -4 addr show tun0 2>/dev/null | grep -oP 'inet \K[\d.]+/\d+') | |
# Try to get IPv4 address and mask from eth0 if tun0 fails | |
eth_info=$(ip -4 addr show eth0 2>/dev/null | grep -oP 'inet \K[\d.]+/\d+') | |
# Decide which to display | |
if [[ -n "$tun_info" ]]; then | |
echo "$tun_info [tun0]" | |
elif [[ -n "$eth_info" ]]; then | |
echo "$eth_info [eth0]" | |
else | |
echo "No IP address found for tun0 or eth0" >&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment