#!/bin/bash

INTERFACE="wlan0"
SUBINTERFACE="wlan0:1"
LOG_FILE="/var/log/network_monitor.log"

while true; do
    # Check if main interface exists
    if ifconfig -a | grep  $INTERFACE >/dev/null 2>&1; then
        # Check if subinterface exists
        if ! ifconfig -a | grep $SUBINTERFACE >/dev/null 2>&1; then
            echo "$(date +'%Y-%m-%d %H:%M:%S') - $SUBINTERFACE does not exist, creating..." >> $LOG_FILE
                        ip addr add "169.254.0.101/16" broadcast 169.254.255.255 dev $INTERFACE label $SUBINTERFACE
            echo "$(date +'%Y-%m-%d %H:%M:%S') - $SUBINTERFACE created successfully" >> $LOG_FILE
        fi
    else
        echo "$(date +'%Y-%m-%d %H:%M:%S') - $INTERFACE does not exist, logging warning..." >> $LOG_FILE
        logger "Warning: $INTERFACE does not exist!"
    fi
    
    # Sleep for 30 seconds
    sleep 30
done

