Courseiva
hardMultiple Choice

350-401 Practice Question: An engineer is writing a Python script to parse…

An engineer is writing a Python script to parse the output of 'show ip interface brief' from multiple Cisco routers. The engineer uses the netmiko library to collect the output and then uses regular expressions to extract the interface name, IP address, and status. The script works correctly for most routers, but on one router, the output format is slightly different (e.g., extra spaces or different column headers). The engineer wants to make the parsing more robust. What is the best approach?

⚠ Common exam trap

Cisco often tests the misconception that regular expressions alone are sufficient for parsing CLI output, but the trap here is that TextFSM is the industry-standard tool for robustly handling semi-structured network device output, not just regex or positional splitting.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

Use the 'textfsm' library with a pre-defined template for 'show ip interface brief'.

TextFSM is specifically designed to parse semi-structured CLI output from network devices. By using a pre-defined template for 'show ip interface brief', the engineer can handle variations in whitespace, column headers, and formatting without writing custom code for each router. This approach is more maintainable and robust than manual parsing methods.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    Write a custom parser that handles each router's output format individually.

    Why it's wrong here

    A custom parser written for each router's output format is unsustainable in a heterogeneous network because every vendor, platform, and software version can introduce subtle differences in column headers, spacing, and line wrapping. This approach also duplicates logic and creates a maintenance burden whenever OS updates occur, and it does not scale as new device types are added. In contrast, TextFSM templates separate the parsing rules from the Python code, so the same template can be reused across many devices.

  • ✗

    Use the 'split()' method to tokenize each line and then extract the relevant fields by position.

    Why it's wrong here

    Using the split() method to tokenize each line and extract fields purely by position assumes a fixed column order and consistent whitespace, which is rarely guaranteed in real 'show ip interface brief' output. When interfaces wrap onto multiple lines, protocols show additional flags, or the header is localized, the indexes shift and the parser silently returns wrong data. TextFSM avoids this by matching named fields with regex rules rather than relying on positional offsets.

  • ✓

    Use the 'textfsm' library with a pre-defined template for 'show ip interface brief'.

    Why this is correct

    The TextFSM library with a pre-defined template is correct because it applies a state-machine-driven set of regex rules to map the human-readable 'show ip interface brief' output into structured values like interface, IP address, status, and protocol. Templates are reusable across different IOS versions and even between vendors because they tolerate extra spaces and optional lines, and they produce clean lists of dictionaries for Jinja2 or Netmiko workflows. This is the standard approach used by ntc-templates and Ansible for reliable CLI parsing.

  • ✗

    Use the 're' module with a more complex regular expression that accounts for optional whitespace.

    Why it's wrong here

    While a single regular expression with \s* can tolerate optional whitespace, it quickly becomes an unreadable monolith that must encode every possible output variation into one pattern, including header lines, blank lines, and wrapped entries. Any new field or format change requires rewriting the entire regex, and debugging state across a line-by-line stream is still not handled cleanly. TextFSM manages this through smaller per-line regexes with named captures and state transitions, making it far more maintainable.

Go deeper

Related to this question

About these practice questions

This 350-401 question is part of Courseiva's 1,923-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 350-401 practice question is part of Courseiva's free Cisco certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 350-401 exam.