getIpLocation() {
    local user_ip="$1"
    local geo city country org

    # Regex RFC1918 (LAN)
    if [[ $user_ip =~ ^127\.|^10\.|^172\.(1[6-9]|2[0-9]|3[0-1])\.|^192\.168\. ]]; then
        echo "Local Network (LAN)"
    else
        if command -v curl >/dev/null 2>&1; then
            # Appel API ipinfo.io
            geo=$(curl -s "https://ipinfo.io/${user_ip}/json")

            if command -v jq >/dev/null 2>&1; then
                # Utilisation de JQ pour un parsing robuste
                echo "$geo" | jq -r '"\(.city), \(.country) (ISP: \(.org))"'
            else
                # Fallback grep/cut si JQ absent
                city=$(echo "$geo" | grep '"city"' | cut -d'"' -f4)
                country=$(echo "$geo" | grep '"country"' | cut -d'"' -f4)
                org=$(echo "$geo" | grep '"org"' | cut -d'"' -f4)
                echo "$city, $country (ISP: $org)"
            fi
        else
            echo "Unknown (curl missing)"
        fi
    fi
}
