SMTP認証失敗したIPを多い順からならべる

Postfix

SMTP認証を試すボットが増えてきました。そのせいかSMTPソケットがいっぱいになり送信失敗になることがでてきました。

そういうIPは拒否しないといけませんので、上位50(間近24時間)を出力するコマンドです。

journalctl -u postfix -S -24h --no-pager \
| grep -E 'postfix/(submission/)?smtpd.*(SASL .* authentication failed|authentication failed|lost connection after AUTH)' \
| awk '{
    ip=""; s=$0;
    while (match(s, /\[([0-9A-Fa-f:.]+)\]/, m)) { ip=m[1]; s=substr(s, RSTART+RLENGTH) }
    if (ip != "" && ip !~ /^[0-9]+$/) c[ip]++
}
END{
    print "回数\tIPアドレス";
    for (i in c) printf "%d\t%s\n", c[i], i
}' \
| sort -nr | head -50

Postfix