Write a program that takes filename as input(apache logfile), depending on the command line arguments(-u or -t) writes to a file:
A. The list of all unique clients in the logfile to a text file (-u)
B. The list of all the unique clients to a text file sorted by number of requests they made. (-t)
Find all the unique clients
Given, an apache logfile and command line option
-u Find all the unique clients in the file and write the list of these clients to a file.
$ python logparser.py -u access.log #Should write all the unique clients to a file [*] created unique_clients.txt $ ./cat.py unique_clients.txt #Using our previous cat program to extract contents unique_clients_get.txt ---------------------- 10.54.89.11 126.96.36.199 iktel.cabel.net mxt.dsl.net
- Understand the apache log entries pattern and use regex to extract clients addresses(There are IPs and hostnames, choose your regex to include both)
- set is a data structure that contains only unique elements.
Sort clients by number of requests
If the user provides a command line option
-t count the number of requests each unique client has made and sort them by number they made and write the sorted data to a file.
$ python logparser.py -t access.log #Should write all the unique clients, number of requests they made(sorted by requests) to a file [*] created clients_requests.txt $ ./cat.py clients_requests.txt #Using our previous cat program to extract contents 10.54.89.11 made 652 requests 188.8.131.52 made 489 requests mxt.dsl.net made 168 requests iktel.cabel.net made 52 requests