Sample Header Ad - 728x90

How to search for 3 specific things within a file?

0 votes
2 answers
99 views
Within the file, security.log I need to find how many IP addresses have the most DNSBL 5 rankings. This is what a line in this file can look like:
Oct 24 00:00:28 MAIL-00 postfix/postscreen: dnsbl rank 5 for [103.129.47.51]:50807
To filter out IP addresses with DNSBL rankings, I did:
grep "ip" security.log | grep -i "DNSBL" security.log
Or I could write a shell script to help, I was thinking something like:
#!/bin/bash

#grep every ip with "dnsbl rank 5"
#count the amount of times each unique one appears, create variable with IP and value is the number of times it appears
#Find the variable with the biggest value and output the variable name to screen
The script would need to cut out the other stuff, so the output to search from is just a list of IPs that had "dnsbl ran 5" before it. I haven't used cut in a long time, would that be the best way to only get the IP inside the brackets? If someone could help me out, I'd really appreciate it!
Asked by echo_LOGNAME (1 rep)
Mar 9, 2022, 05:55 PM
Last activity: Mar 10, 2022, 05:11 AM