Home > sysadmin > Handy script to parse Postfix maillogs for failed login IP addresses

Handy script to parse Postfix maillogs for failed login IP addresses

You can use the script below to parse your maillog (mail.log on Debian based distros) for failed login attempts and place the results in your hosts.deny file or your IP tables config. The script deletes leading 0 IP addresses and filters out [brackets]. You can change the grep filter phrase to your liking.

grep “failed” /var/log/maillog | grep -Eo “([0-9]{1,3}.){3}[0-9]{1,3}” | sed ‘s/^[0]*//’ | uniq

Categories: sysadmin
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: