0
0
Cybersecurityknowledge~10 mins

Log analysis techniques in Cybersecurity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read a log file line by line.

Cybersecurity
with open('system.log', '[1]') as file:
    for line in file:
        print(line.strip())
Drag options to blanks, or click blank then click option'
Awrite
Bdelete
Cappend
Dread
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'write' mode will erase the file contents before reading.
2fill in blank
medium

Complete the code to filter log lines containing the word 'ERROR'.

Cybersecurity
error_lines = [line for line in log_lines if '[1]' in line]
Drag options to blanks, or click blank then click option'
AERROR
BWARNING
CINFO
DDEBUG
Attempts:
3 left
💡 Hint
Common Mistakes
Filtering by 'INFO' or 'DEBUG' will include less critical messages.
3fill in blank
hard

Fix the error in the code to parse timestamps from log entries.

Cybersecurity
from datetime import datetime

log_time = datetime.strptime(log_entry['timestamp'], '[1]')
Drag options to blanks, or click blank then click option'
A%Y/%m/%d %H:%M:%S
B%Y-%m-%d %H:%M:%S
C%d-%m-%Y %H:%M:%S
D%m-%d-%Y %H:%M:%S
Attempts:
3 left
💡 Hint
Common Mistakes
Using slashes or wrong order causes parsing errors.
4fill in blank
hard

Fill both blanks to create a dictionary of IP addresses and their counts from logs.

Cybersecurity
ip_counts = {ip: [1] for ip in ip_list if ip [2] ip_list}
Drag options to blanks, or click blank then click option'
Aip_list.count(ip)
Blen(ip_list)
Cin
Dnot in
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'not in' will exclude IPs instead of including them.
5fill in blank
hard

Fill all three blanks to filter logs by severity and create a summary dictionary.

Cybersecurity
summary = [1] for entry in logs if entry['severity'] [2] 'high' and entry['status'] [3] 'open'
Drag options to blanks, or click blank then click option'
A{entry['id']: entry['message']}
B==
C!=
D{entry['message']: entry['id']}
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up keys and values in the dictionary or using wrong comparison operators.