Sign inSign up free

1456. Top Client IPs From an Access Log

easy 10 XP ~10 minHands-on lab

During an incident you keep running awk | sort | uniq -c | sort -rn | head on access logs. Turn it into a tool the team can rely on. The starter is /home/student/logs/top_ips.py; a sample log is next to it.

python3 top_ips.py LOGFILE N

Task

  • Print the N client IPs with the most requests, one per line, as COUNT IP (for example 42 10.0.3.7).
  • Most requests first; when two IPs have the same count, sort those by IP as text.
  • If there are fewer than N different IPs, print them all.
  • The client IP is the first field of each line. Your script is graded on logs it hasn't seen.

About this machine

Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.

Part of Python for DevOps. Next step: Totals per Column From a Real CSV

Teaching or writing about this? Embed this lab on your page

TerminalNot started

Your machine is ready to start

A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.

No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.