I'm working on a distributed fail2ban like system in perl/mysql/iptables.
Extracting ipv4 addresses from /var/log/messages is working, but now I want to add /var/log/maillog to the soup.
I have a perl regex:[1]
/ (?:25[012345]|2[0-4]\d|1?\d\d?)\.
(?:25[012345]|2[0-4]\d|1?\d\d?)\.
(?:25[012345]|2[0-4]\d|1?\d\d?)\.
(?:25[012345]|2[0-4]\d|1?\d\d?) /x
And a line from maillog:
v817YjcU016645: 194.102.60.190.host.ifxnetworks.com [190.60.102.194] did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA
Here the regex matches both 194.102.60.190
.host.ifxnetworks.com
and [190.60.102.194
]
In my code I have ($IP is the above regex):
if ($line =~ m/($IP)/)
{
my ($ip) = $1;
Here the first matching ip-like string is found 194.102.60.190
.host.ifxnetworks.com
So, how do I get the regex to ignore an ipv4 that ends in a .
[1] for readability Perl supports the /x option
/...(?!\.)/
– zdim194.102.60.19
0.host.ifxnetworks.com – Mogens TrasherDKmy ($IP) = $OCT . '\.' . $OCT . '\.' . $OCT . '\.' . $OCT
:) – Mogens TrasherDK