nerdexam
Cisco

300-215 · Question #98

Which scripts will search a log file for the IP address of 192.168.100.100 and create an output file named parsed_host.log while printing results to the console? A. B. C. D.

The correct answer is D. import os import re line_regex = re.compile(r".*fwd=\192\\.168\\.100\\.100\\W.*$") output_filename = os.path.normpath("output/parsed_host.log") with open(output_filename, "w") as out_file: out_file.write("") with open("test_log_log", "r") as in_file: for line in in_file: if (line_regex.search(line)): print line with open("parsed_host.log", "a") as out_file: out_file.write(line). Option D is correct because it properly creates 'parsed_host.log' as the output file (matching the required filename), reads from the log file ('test_log_log') in read mode, prints each matching line to the console, and appends matching lines to 'parsed_host.log'. The script…

Submitted by chiamaka_o· Mar 6, 2026Automation and Scripting / Security tool development - understanding Python file handling, regex searching, and output redirection as applied to cybersecurity log analysis tasks (e.g., CompTIA CySA+ or Security+ scripting objectives)

Question

Which scripts will search a log file for the IP address of 192.168.100.100 and create an output file named parsed_host.log while printing results to the console? A. B. C. D.

Exhibits

300-215 question #98 exhibit 1
300-215 question #98 exhibit 2
300-215 question #98 exhibit 3
300-215 question #98 exhibit 4

Options

  • Aimport os import re line_regex = re.compile(r".fwd=\192\.168\.100\.100\W.$") output_filename = os.path.normpath("output/parsed_host.log") with open(output_filename, "w") as out_file: out_file_write("") with open("output/filename_","a") as out_file: with open("parsed_host.log", "r") as in_file: for line in in_file: if (line_regex.search(line)): print line out_file.write(line)
  • Bimport os import re line_regex = re.compile(r".fwd=\192\.168\.100\.100\W.$") output_filename = os.path.normpath("output/parsed_host.log") with open(output_filename, "w") as out_file: out_file.write("") with open("test_log_log", "a") as out_file: with open("parsed_host_log", "r") as in_file: for line in in_file: if (line_regex.search(line)): print line out_file.write(line)
  • Cimport os import re line_regex = re.compile(r".fwd=\192\.168\.100\.100\W.$") output_filename = os.path.normpath("output/parsed_host.log") with open(output_filename, "w") as out_file: out_file.write("") with open("parsed_host.log", "a") as out_file: with open("test_log_log", "r") as in_file: for line in in_file: if (line_regex.search(line)): print line out_file.write(line)
  • Dimport os import re line_regex = re.compile(r".fwd=\192\.168\.100\.100\W.$") output_filename = os.path.normpath("output/parsed_host.log") with open(output_filename, "w") as out_file: out_file.write("") with open("test_log_log", "r") as in_file: for line in in_file: if (line_regex.search(line)): print line with open("parsed_host.log", "a") as out_file: out_file.write(line)

How the community answered

(29 responses)
  • A
    3% (1)
  • B
    7% (2)
  • C
    3% (1)
  • D
    86% (25)

Explanation

Option D is correct because it properly creates 'parsed_host.log' as the output file (matching the required filename), reads from the log file ('test_log_log') in read mode, prints each matching line to the console, and appends matching lines to 'parsed_host.log'. The script correctly initializes the output file with an empty write, then reopens it in append mode inside the loop to capture results while simultaneously printing to the console.

Topics

#Python scripting#log parsing#regular expressions#file I/O

Community Discussion

No community discussion yet for this question.

Full 300-215 Practice