Created
September 9, 2020 18:47
-
-
Save renexu/d47b9453c4aa52b02e05e08b97ffec40 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from argparse import ArgumentParser | |
from collections import defaultdict | |
if __name__ == '__main__': | |
parser = ArgumentParser() | |
parser.add_argument('input', type=str) | |
args = parser.parse_args() | |
count = 0 | |
ip_count = defaultdict(int) | |
http_code_count = defaultdict(int) | |
total_time_spent = 0 | |
with open(args.input, mode='r') as f: | |
entry = f.readline() | |
while entry: | |
count += 1 | |
entry = entry.replace('\n', '') | |
parts = entry.split() | |
ip = parts[0] | |
http_code = parts[8] | |
response_time = int(parts[-1]) | |
ip_count[ip] = ip_count[ip] + 1 | |
http_code_count[http_code] = http_code_count[http_code] + 1 | |
total_time_spent += response_time | |
# print(ip, http_code, response_time) | |
entry = f.readline() | |
print('number of entries', count) | |
print('ip address', 'count') | |
for ip, count in ip_count.items(): | |
print(ip, count) | |
print('http code', 'count') | |
for http_code, count in http_code_count.items(): | |
print(http_code, count) | |
print('total time spent', total_time_spent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment