#!/bin/sh

# Function to check internet connectivity
check_internet() {
    host="8.8.8.8"

    ping -c 3 $host > /dev/null 2>&1

    if [ $? -eq 0 ]; then
        return 0  
    else
        return 1  
    fi
}

# Function to check WLAN status
check_wlan() {
    if [[ $(nmcli -t -f WIFI g) == "enabled" ]]; then
        if [[ $(nmcli -t -f STATE g) == "connected" ]]; then
            check_internet
            if [ $? -eq 0 ]; then
                return 0  
            else
                return 1  
            fi
        else
            return 2  # WLAN Disconnected
        fi
    else
        return 2  # WLAN Disconnected
    fi
}

check_wlan

case $? in
    0)
        echo "WLAN Connected"
        ;;
    1)
        echo "[!] WLAN Connected"
        ;;
    2)
        echo "WLAN Disconnected"
        ;;
esac
