Fetching Running Configuration Over Telnet with Python

H12-811 By islever Editorial Last updated

Network Programming and Automation Data Communication and Network Basics

Short answer

AB Use telnetlib and telnet.write(b"display current-configuration \n") to send the command and read the device running configuration.

Question

You want to check the running configuration on a device by running a Python script to telnet to the device. Which of the following statements is true?
  1. telnetlib can implement this function. Correct Answer
  2. telnet.write(b"display current-configuration \n") can be used to check the current configurations. Correct Answer
  3. telnet.close() can be used to wait for the device output after each command is entered.
  4. telnet.Telnet(host) can be used to connect to a Telnet server.

Key Takeaways

The test is whether you know which telnetlib method opens the session, which sends a command, and which waits for output — close() terminates rather than waits.

This H12-811 question tests Python telnetlib automation against a network device. The correct choices are A and B: telnetlib provides the connection, and telnet.write sends the display current-configuration command.

Common mistake: Option C is the tempting error: telnet.close() closes the Telnet session instead of waiting for device output; reading requires read_until() or read_very_lazy(). Option D is also invalid because the constructor is telnetlib.Telnet(host), not telnet.Telnet(host).

Expert Analysis

Why A and B are correct Python's standard telnetlib module is exactly the tool for this task: it opens a TCP connection to the device's Telnet service, so option A is true. Once you have an instance — telnet = telnetlib.Telnet(host) — the write method pushes bytes down the socket, and a Huawei VRP command such as display current-configuration is a valid way to retrieve the running configuration, so option B is true. Two details matter in practice: the payload must be bytes (hence the b"...\n" literal), and the trailing newline is what actually triggers the CLI to execute the command.

Why C is wrong close only tears down the Telnet session — it releases the socket and ends the process's access to the device. Waiting for output is a read operation, done with methods such as read_until, read_very_lazy or expect, typically after a short sleep or an expect on the prompt. Calling close "after each command" would disconnect you before any reply arrived, so a script written that way returns nothing at all. If you close the session a second time, Python even raises an error on some versions.

Why D is wrong as written The constructor lives on the module, not on an object of an already-created connection. The working form is telnetlib.Telnet(host); telnet.Telnet(host) only works if you explicitly aliased the import (import telnetlib as telnet). Exam wording is literal: evaluate the identifier exactly as printed.

The adjacent decision that flips the answer If the question asked what you must do between commands, the answer would shift to reading output (and often issuing screen-length 0 temporary first so the pager does not stall a long configuration dump). If the scenario switched to SSH, telnetlib would be replaced by paramiko. Also note that telnetlib was deprecated in Python 3.11, so modern automation uses Netmiko/NAPALM or RESTCONF — but for this exam's classic pattern, A and B stand, and getting the wait step wrong silently produces empty or truncated output in production scripts.

Official Reference

https://docs.python.org/3/library/telnetlib.html

This link opens the official vendor documentation in a new tab.

Exam Strategy

Read every option literally as executable code before judging it: check whether the identifier exists (module vs. instance), whether the argument type matches (bytes vs. str), and whether the method's side effect matches the requested action — connect, send, wait, or disconnect. When no selection count is stated, treat the item as multi-select and pick every statement that would run unchanged in a real script.

Frequently Asked Questions

Which telnetlib method waits for the device's reply after a command?

Use telnet.read_until(expected_prompt, timeout) or read_very_lazy()/expect() to collect output. close() only ends the session, so it cannot return the configuration text.

Why does telnet.write require a bytes string like b"...\n"?

telnetlib writes directly to a socket, which transports bytes, not str. The trailing newline is required because the CLI executes the command only when it receives the carriage-return/newline sequence.

Is telnet.Telnet(host) ever a valid call?

Only if you aliased the import as import telnetlib as telnet. With a normal import import telnetlib, the correct constructor is telnetlib.Telnet(host).

More H12-811 FAQ →

Community Votes

A
50%
B
50%

50% of anonymous learners picked answer A. Votes are pick records left by other test-takers — they are not the verified answer.

Discussion 2 contributions

Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.

From public community threads 2

  1. Fmoura17 👍 1
    A. telnetlib can implement this function. ✅ TRUE telnetlib is the correct Python module for Telnet connections to network devices. B. telnet.write(b"display current-configuration \n") can be used to check the current configurations. ✅ TRUE If telnet is the instantiated telnetlib.Telnet object (i.e. telnet = telnetlib.Telnet(host)), then telnet.write() is the correct method to send commands to the device. This statement is technically valid
  2. e9b92a4 👍 1
    Correct answers: A and B D. telnet.Telnet(host) can be used to connect to a Telnet server. ❌ (as written) The correct call is telnetlib.Telnet(host) (assuming import telnetlib). Writing telnet.Telnet(host) is incorrect unless you aliased the module as telnet.

Reader comments & corrections

No reader corrections yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

← Back to H12-811 Study Guide