Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Count apache404 errors ip and join iptables Firewall

Shulou Source: shulou.com Published: 2022-06-01 03:56:35 10月06日 Update

#! / bin/bash

# apache log error missing 404

# get the current log time

Date= `date +% Y% m% d`

# output log files to LOG variables

LOG='pay_access_'$date'.log'

# 404 error filtering

Awk'$9 = = 404 {print $1}'$LOG >. / tmplog

Awk'{a [$0] + +} END {for (i in a) print iCommand a [I]} 'tmplog | sort >. / tmpl

Awk'$2 > 10 {print $1} 'tmpl >. / tmpip

/ etc/init.d/iptables restart

# read the ip; in the file line by line and add it to the iptables firewall

Ip= "tmpip"

While read LINE

Do

Iptables-An INPUT-s $LINE-p tcp-- dport 80-j DROP

Done < $ip

Add disable ip as temporary, so every time you restart the iptables policy, it will clear.

Then add scheduled tasks.

Tags: Logs errors files firewalls fire protection tasks variables time policies output statistics Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker vpn Shulou Information Shulou Technology Huawei