The Telnet protocol allows terminals, or processes,
to interface with each other through the use of standardized commands
and the possibility of additional option requests.
The commands, which are displayed here along with their codes,
include the five standard representations: Interrupt
Process; the Terminated process, like an unending loop; Abort output,
to allow a process to complete without generating any output; Are You There,
to print confirmation that a remote system is still online and active; and,
Erase character; and Erase Line.
These, obviously,
are basic control tools that help manage sessions on a very low level.
All of those commands are effectively built into the normal Telnet
clients that you'll run on your own operating system.
So while you don't need to handle them manually,
being aware of how things work under the hood can
sometimes make troubleshooting a lot easier.
We can also see the WILL, WON'T, DO, and DON'T commands,
which can be used in turn to request, refuse,
start or stop options that add features above and beyond the basic
functionality of the network virtual terminals.
To help you visualize how these things can work,
I'll send a Telnet parameter command from within a normal session,
by escaping the session using the CTRL and right bracket.
This example will list the current environment variables.
You could add a new variable using environ define,
the name of the new variable, and its value.
Listing again, will show us or new variable.
Individual arguments can be sent using the send command.
Here, I'll send an Are You There request to my host.
Send getstatus will return the remote server's current option status.
You can also run commands that login.
This example will launch a Telnet session on my server using the character mode,
which will send commands one character at a time,
rather than line mode.
This can be useful in the very, very, very,
case of a host that doesn't know how to handle line mode.
It's common to import Telnet into scripts using languages like Perl or Python.
To show how that's done,
I'll create a simple bash script that will login to a remote Telnet server,
authenticate, and then run a command to list the files in the current directory,
in this case.
Of course, you should never hardcode a password into a script I'm doing.
But I figure you already saw this password a bit earlier in Wireshark,
so what more do I have to lose.
In this script, I pipe my data into the Telnet command,
along with delays of two seconds to give the host time to
respond with the appropriate prompts.
Let's see how it runs.
On UNIX-based systems,
you should be able to run man telnet for a complete command listing.
I'll use Wireshark to give you a simple illustration of how
Telnet communicates session operations.
I've already got an existing Telnet session in this terminal,
so I'll start Wireshark listening in on my lxcbr0 Network interface for
all the traffic between my Telnet client and host.
And then, within the Telnet session, I'll do nothing more than hit Enter,
move that to Wireshark and stop the capture.
As you can see, there were three packets.
The first Telnet packet was moving from my client to the host,
and as the Telnet part of the packet tells us,
it contained only the \r, or carriage return character,
or, in other words, the Enter key that I just hit.
The second Telnet packet contains a reply from host echoing the \r,
along with a line feed \n,
and then sending the new command prompt to be displayed in the client's terminal.