|
|
#!/bin/sh
# Script by oldpiano
DATE=`date +%Y-%m-%d' '%H:%M:%S`
CNT=0
echo "" > /tmp/spamer
if [ -e /var/log/maillog ]; then
for i in $( cat /var/log/maillog | awk '/User unknown$/ {print $6}' | uniq ); do
cat /var/log/maillog | awk -F 'relay=' '/'$i'.*relay\=/ {print $2}' >> /tmp/spamer
done
fi
awk '{gsub(/^.*\[/,"");gsub(/\].*$/,"");print $0}' /tmp/spamer | sort | uniq -c > /tmp/spamer
for i in $( cat /tmp/spamer | awk '$1 > 1 {print $2}' ); do
#ip format ::ffff:0.0.0.0
denyip=${i#::ffff:}
if [ ! $( cat /etc/mail/access | awk '{print $1}' | grep $denyip ) ]; then
CNT=$(($CNT + 1))
echo "$denyip REJECT" >> /etc/mail/access
fi
done
if [ $CNT = 0 ]; then
exit
fi
echo "# --- added at $DATE" >> /etc/mail/access
mail -s 'Denied Spamer' [메일주소] < /etc/mail/access
makemap -v hash /etc/mail/access.db < /etc/mail/access #> /dev/null
service sendmail restart #> /dev/null
[출처] Sendmail 스패머 IP 차단 쉘스크립트 v2|작성자 oldpiano