Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 37 ยท Projects and Practice

Project: A Network Log Analyzer

Build a complete log analyzer in Python: parse firewall and web logs, detect scans, brute force and suspicious requests, rank sources by risk and produce a readable incident report.

In this project you will combine skills from the whole chapter into one working tool: a log analyzer that reads firewall, authentication and web-server logs, applies several detections and prints a ranked report an analyst could act on. You will build it in stages, each stage runnable on its own, using only Python's standard library and invented sample data (no real network is touched).

The finished tool answers: Which source addresses behaved suspiciously, why, and how worried should we be? It uses the ideas from log analysis, signature detection and anomaly baselines.

flowchart LR
    L["Raw logs<br/>firewall, auth, web"] --> P["Parsers"]
    P --> E["Normalized events"]
    E --> D1["Port scan detector"]
    E --> D2["Brute-force detector"]
    E --> D3["Web signature detector"]
    D1 --> S["Scoring per source IP"]
    D2 --> S
    D3 --> S
    S --> R["Ranked report"]

Stage 1: parse three formats into one event shape

Every parser outputs the same dictionary: time (seconds), src, kind and details. Normalizing early makes every detector simple.

Python Stage 1: parsers and normalization

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The walrus operator (:=) assigns and tests in one step, which keeps the parser chain compact. Note the unparsed counter: it is your health check for format drift.

Stage 2: three detectors

Each detector takes the list of events and returns findings: (source, name, points, detail). Points express how strongly the finding suggests malicious intent.

Python Stage 2: detectors

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Each detector is small and testable by itself. When you later add a detector for DNS or VPN logs, nothing else changes.

Stage 3: score, rank and report

Sum the points per source, classify by thresholds and print a report with the evidence and a recommended action. This turns a pile of findings into a prioritized to-do list.

Python Stage 3: scoring and the report

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first source reaches CRITICAL because several independent signals line up: a scan, guessing, a successful login after failures and web attack patterns. A single odd request alone would stay LOW.

Extending the project

Pick any of these to make it your own:

  1. Time windows: only count failures inside a 60-second window, as in the rate-based thresholds.
  2. Allow-list known scanners (your own vulnerability scanner) so they do not alert.
  3. GeoIP and reputation: enrich sources with a country and a local block-list file.
  4. Output formats: write JSON for a SIEM and a short text summary for email.
  5. Baselines: compare each source's request rate with its history (anomaly detection).
  6. Unit tests: write a test for each detector with a few attack and benign examples; false-positive tests matter as much as detections.
  7. Streaming mode: process lines as they arrive and keep only a sliding window in memory.

Design principles you practiced: normalize early, keep detectors independent, count unparsed input, attach evidence to every alert, and rank so a human reads the worst first.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does every parser output the same event shape?

    Normalized events decouple parsing from detection.
  2. 2. Why is the 'login after failures' finding worth extra points?

    That sequence is the strongest evidence that guessing worked and the account may be compromised.
  3. 3. What does the unparsed-lines counter protect against?

    A rise in lines that no parser recognizes means events are being missed.
  4. 4. Why rank sources by summed score instead of alerting on each finding separately?

    Several weak signals together are stronger than any single one, and ranking directs attention.

Summary

  • You built a pipeline: parse, normalize, detect, score, report.
  • Independent detectors for scans, password guessing and malicious web requests share one event format.
  • Scoring combines evidence per source and maps it to a severity and a recommended action.
  • Good tools count unparsed input, show evidence and are easy to extend and test.

Next: Project: Scanning Your Own Loopback Ports