#!/bin/bash
iface=$(ip route show default 2>/dev/null | awk '/default/ {for (i=1; i<=NF; i++) if ($i == "dev") print $(i+1)}')

if [[ ! $iface =~ ^(eth|en|wlan) ]]; then
    echo "Default interface ($iface) is not a physical interface. Select a physical interface:"
    interfaces=($(ip link show up | awk -F': ' '{print $2}' | grep -E '^(eth|en|wlan)' | sort))
    
    if [ ${#interfaces[@]} -gt 0 ]; then
        select choice in "${interfaces[@]}"; do
            if [ -n "$choice" ]; then
                iface=$choice
                break
            else
                echo "Invalid selection. Try again."
            fi
        done
    else
        echo "No physical interfaces found."
        exit 1
    fi
fi

ip4=$(ip -4 addr show "$iface" | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n 1)
gw=$(ip route show dev "$iface" | awk '/via/ {print $3; exit}')
ip6=$(ip -6 addr show "$iface" | grep -oP '(?<=inet6\s)(?!fe80)[\da-f:]+(?=/)' | head -n 1)

echo "[\`$iface\`, \`$ip4\`, \`$gw\`, \`$ip6\`]"

