Using the telnet protocol in Python

Telnet is one of the oldest protocols available in the TCP/IP stack. It is used primarily to exchange data over an established connection between a server and client. It uses TCP port 23 in the server for listening to the incoming connection from the client.

In our case, we will create a Python script that acts as a telnet client, and other routers and switches in the topology will act as the telnet server. Python comes with a native support for telnet via a library called telnetlib so we don't need to install it.

After creating the client object by instantiating it from the Telnet() class, available from the telnetlib module, we can use the two important functions available inside telnetlib, which are ...

Get Hands-On Enterprise Automation with Python. now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.