Video summary

Python learning for Network Engineers Part 06 | First script using telnetlib in Python 2 & Python 3

Main summary

Key takeaways

Technology

In this video, the presenter demonstrates how to write a basic Python script using the telnetlib library to connect to a router and retrieve output. The focus is on creating a simple script suitable for beginners, with a comparison between Python 2 and Python 3.

Key Concepts and Features:

  • Telnet Library: The video covers the use of the telnetlib library, which allows for Telnet connections to devices.
  • Python Versions: The presenter uses both Python 2.7 and Python 3.6 to illustrate differences in syntax and functionality, especially concerning the telnetlib library.
  • virtual environments: The video discusses setting up virtual environments to manage different Python versions.
  • Common Issues: The presenter encounters issues with the Python 2 console and resolves them by installing the readline tool, which is necessary for proper console input handling.
  • Basic Script Creation: A basic script is created to perform a Telnet connection, where the script prompts for a username and password, executes commands, and retrieves output.
  • Variable Use: The presenter explains how to define variables for commands, usernames, and passwords, allowing for dynamic input.
  • Encoding Differences: In Python 3, additional considerations for byte encoding and decoding are introduced, such as using b in front of strings and changing raw_input to input.
  • Best Practices: The video emphasizes the importance of setting terminal length to zero to prevent the script from hanging during output retrieval.

Product Features:

  • Telnet Class: The telnetlib provides a Telnet class for establishing connections to Telnet servers.
  • Methods: The library includes various methods like read_all(), read_some(), and read_very() for handling data from the server.

Upcoming Content:

The presenter hints at future videos that will delve deeper into Python programming concepts such as modules, classes, and functions, as well as further scripting with telnetlib.

Main Speakers/Sources:

Original video