ddos-mitigator/mitigate-ddos/ddos-mitigator.sh

20 lines
559 B
Bash
Executable File

#!/bin/sh
input_files=/var/log/apache2/access_*.log
tmpdir=$(mktemp -d)
cd "${tmpdir}"
cut -d' ' -f1 ${input_files} | sort > all.txt
grep ':' all.txt > raw-ipv6.txt
grep -v ':' all.txt > raw-ipv4.txt
uniq -c raw-ipv6.txt | sort -n > sorted-ipv6.txt
uniq -c raw-ipv4.txt | sort -n > sorted-ipv4-32.txt
cut -d. -f1-3 raw-ipv4.txt | sort | uniq -c | sort -n > sorted-ipv4-24.txt
cut -d. -f1-2 raw-ipv4.txt | sort | uniq -c | sort -n > sorted-ipv4-16.txt
cut -d. -f1 raw-ipv4.txt | sort | uniq -c | sort -n > sorted-ipv4-8.txt
echo "Have fun in ${tmpdir}!"