The Telnet Class
Syntax: class telnetlib.Telnet(host=None, port=0[, timeout]) :
Input Parameters:
- host(optional): it takes the server name or ip-address. Example: 127.0.0.1, “localhost”
- port(optional): takes the port number if not provided uses the default port number.
- timeout(optional): an additional parameter can be passed to specify the timeout duration else the global timeout duration is used.
If the Telnet object is created without any parameters, a connection can be established by calling the open() method. Alternatively, the user can pass the host and port details, in which case the object is returned with a connection established.
WARNING: A lot of functions in the Telnet class raise EOFError. Hence, appropriate exception handling must be done.
Important Functions:
- Telnet.read_until(expected, timeout=None)
- Telnet.read_all()
- Telnet.open(host, port=0[, timeout])
- Telnet.close()
- Telnet.write(buffer)
- Telnet.interact()
We have explained the usage of the functions in the following code.
Telnet – Python Network programming
Telnet is a networking protocol that follows a client-server model. It uses TCP as its underlying communication protocol. It is typically used to start and a remote command-line session, typically on a server.
Some facts about telnet:
- Uses Transmission Control Protocol for data transmission.
- Bi-directional 8-bit protocol
- The protocol standard was initially described in RFC15 and was further extended in RFC854 and RFC855.
- It was developed in 1969.
In python, telnet communication is facilitated by the telnetlib module. The telnetlib module provides Telnet class that implements telnet protocol described in RFC 854.