#!/bin/bash


# Cooja log file path

LOGFILE="/home/user/Desktop/wspcap/cooja_log"


# Cooldown time in seconds (300 = 5 minutes)

COOLDOWN=300


# Last SMS sent time

LAST_SENT=0


echo "======================================"

echo " Real-Time WSN Attack Monitoring "

echo "======================================"


# Continuously monitor log file

tail -f "$LOGFILE" | while read LINE

do


    # Print live log line

    echo "$LINE"


    # Check for attack pattern

    if echo "$LINE" | grep -q "Sinkhole attack"

    then


        CURRENT_TIME=$(date +%s)


        TIME_DIFF=$((CURRENT_TIME - LAST_SENT))


        # Check cooldown

        if [ $TIME_DIFF -ge $COOLDOWN ]

        then


            echo ""

            echo "⚠️ Sinkhole attack detected!"

            echo "📡 Sending SMS alert..."

            echo ""


            # ==========================================

            # Paste your Twilio curl SMS command here

            # ==========================================



            # Update last sent time

            LAST_SENT=$CURRENT_TIME


        else


            REMAINING=$((COOLDOWN - TIME_DIFF))


            echo ""

            echo "⏳ Cooldown active."

            echo "📵 SMS skipped."

            echo "⌚ Wait $REMAINING more seconds."

            echo ""


        fi


    fi


done

Comments

Popular posts from this blog

networks and security cia 1

GATE SYLLABUS FOR ECE