Log Analyzer with python.
Building a Log Analyzer with Python that Detects Brute-Force on SSH Logs
Problem:
Logs are messy and difficult to read, especially when there’s no SIEM tool available in your toolkit and you have a large number of logs to go through. A Python script can offer you a way to extract the logs in an easy-to-read format, with analysis built in.
The raw data
A typical SSH auth log line looks like this:
2026-09-24T16:43:33.513487+01:00 Root sshd-session[102527]: Failed password for invalid user baduser from ::1 port 50960 ssh2This is just text, before it is useful each individual field has to be extracted(the timestamp, source IP, and username need to be pulled out into structured data.) This is where regular expression(regex) comes in.
Step 1: Parsing the logs
I wrote regex patterns for the three event types that matter most: failed logins, connection closures, and successful logins.
Each match becomes a dictionary: timestamp, PID, user, IP, port, and an event label. The parser reads the file line by line, so it stays memory efficient even on large logs, no loading the whole file into memory at once.
Step 2: Analysis
Get Akinola selim’s stories in your inbox
Join Medium for free to get updates from this writer.
With structured records, we can now count the logs, collections.Counter does the counting: which IP attacked the most, which usernames were targeted, and failed logins broken down by hour.
Step 3: Detecting brute-force success
Counting the number of failed attempts alone is not enough. The real question is: did a brute-force attempt actually succeed? The tool tracks a running failure count per IP. When that IP logs in successfully, it checks how many failures came right before it.
Severity scoring helps differentiate between alerts. An IP that fails 18 times then logs in is a very different event from one that fails once and gets in on the second attempt.
Output
Findings print to the terminal as a readable summary, and also get saved to JSON for use elsewhere.
Scope
This tool reads SSH auth logs specifically, the full code is on my github.








