Untitled
unknown
plain_text
19 days ago
818 B
3
Indexable
Never
# Sample logs lines = ["10.0.0.1 - GET 2020-08-24", "10.0.0.1 - GET 2020-08-24", "10.0.0.2 - GET 2020-08-20"] def count_ip(lines): # Dictionary to store the count of each IP address ip_count = {} result = [] max_count = 0 # Iterate through each log line for line in lines: # Split the line by spaces and get the IP address (first element) ip_address = line.split()[0] # Increment the count of the IP address in the dictionary if ip_address in ip_count: ip_count[ip_address] += 1 else: ip_count[ip_address] = 1 max_count = max(max_count, ip_count[ip_address]) for key, value in ip_count.items(): if value == max_count: result.append(key) return result # Display the result ip_count
Leave a Comment