Bash code for analyzing web server traffic to determine which ip accessed the web server the most

#!/bin/bash
# Check if a log file was specified
if [ "$#" -ne 1 ]; then
echo "Usage: $0 access.log"
exit 1
fi
LOG_FILE="$1"
if [ ! -f "$LOG_FILE" ]; then
echo "Error: Log file does not exist."
exit 1
fi
TOP_IPS=10
# Analyze the log file to find the top IP addresses
echo "Analyzing the log file to find the top $TOP_IPS IP addresses..."
awk '{print $1}' "$LOG_FILE" | sort | uniq -c | sort -nr | head -n "$TOP_IPS" | awk '{print "IP: " $2 ", Access Count: " $1}'

This handy script is useful for webserver traffic analysis task. It can be use to detect abusive IP address or spambots which accesses the webserver.

ystem administrators can utilize the generated list of IP addresses to enhance webserver security by blocking those IPs deemed potentially harmful or suspicious.