π ByteDrop #003: Python Log Sniffer
Scenario: Youβre investigating a log file for repeated IP addresses. The goal is to identify any IPs that show up more than once β a common sign of scanning or brute-force attempts.
Challenge: Complete the Python script below to print all IPs that appear more than once.
log_data = [
"192.168.1.10 - login attempt",
"10.0.0.5 - login attempt",
"192.168.1.10 - login attempt",
"172.16.0.2 - login attempt",
"10.0.0.5 - login attempt"
]
ip_counts = {}
for entry in log_data:
ip = entry.split(" ")[0]
# TODO: Count each IP address
# TODO: Print IPs that appear more than once
What should go in the two TODO sections?
π½ Need help? Click to reveal tips
- Use a dictionary to count how many times each IP appears.
- Use `.get()` to safely increment values.
- Loop through the dictionary to find values greater than 1.