Telnet

Intro


Telnet is a computer protocol that was built for interacting with remote computers.
The word “Telnet” also refers to the command-line utility “telnet”, available under Windows OS and Unix-like systems, including Mac, Linux, and others. We will use the term “Telnet” mostly in the context of the telnet client software.
Telnet utility allows users to test connectivity to remote machines and issue commands through the use of a keyboard. Though most users opt to work with graphical interfaces, Telnet is one of the simplest ways to check connectivity on certain ports.

Enable telnet client in Windows

Telnet is disabled by default in Window’s settings, so you need to turn it on before you can do anything. Turning it on will help you to run the required diagnostics and check if a port is open. If you try to use telnet without turning it on first, you’ll receive a message like: 

 ‘telnet’ is not recognized as an internal or external command, operable program or C:\>

Enabling telnet client through Command Prompt:
Install-WindowsFeature -name Telnet-Client

Enabling telnet client via GUI Win10:
Open Windows Start menu > Type “Control Panel” > Press Enter > “Programs” > “Programs and Features” > Turn Windows features on or off > Select “Telnet Client” > Press “OK”

Enabling telnet client via GUI WS2012+:
Open “Server Manager” > “Add roles and features” > click “Next” until reaching the “Features” step > tick “Telnet Client” > click “Install” > when the feature installation finishes, click “Close”.

Telnet Commands List

Type thisTo do this
open or oEstablish a Telnet connection with a host computer or remote server. You can use the full command, open, or abbreviate it to just o. For example,  o domain.com 25 will connect your computer to a computer named  domain.com port 25.
displayView the current settings for Telnet Client.
Type display for a list of the current operating parameters. If you are in a Telnet session (connected to a Telnet server), to modify the parameters, press Ctrl+] to leave the Telnet session. To return to the Telnet session, press Enter. The following operating parameters are available:
WILL AUTH (NTLM Authentication)
WONT AUTH
WILL TERM TYPE
WONT TERM TYPE
LOCALECHO off
LOCALECHO on
quit or qExit from Telnet.
set Set the terminal type for the connection, turn on local echo, set authentication to NTLM, set the escape character, and set up logging.
>SET NTLM turns on NTLM. While you are using NTLM authentication, if you’re connecting from a remote computer, you will not be prompted to type a logon name and password.
> SET LOCALECHO turns on local echoing.
> SET TERM {ANSI|VT100|VT52|VTNT} sets the terminal type to the appropriate terminal type.
You should use the VT100 terminal type if you are running normal command-line applications. Use the VTNT terminal type if you are running advanced command-line applications, such as .
> ESCAPE + Character sets the key sequence to use for switching from session to command mode. For example, to set Ctrl+P as your escape character, typeset escape, press Ctrl+P, and then press Enter.
> LOGFILE FileName sets the file to be used for logging Telnet activity. The log file must be on your local computer. Logging begins automatically when you set this option.
> LOGGING turns on logging. If no log file is set, an error message is displayed.
unsetTurn off local echo or set authentication for the logon or password prompt.

UNSET NLM turns off NLM.
UNSET LOCALECHO turns off local echoing.
statusMove to the Telnet command prompt from a connected session
enterGo to the connected session (if it exists)
?/helpView Help information

Parameter List

ParameterDescription
/aattempt automatic logon. Same as /l option except uses the currently logged on user s name.
/e <EscapeChar>Escape character used to enter the telnet client prompt.
/f <FileName>File name used for client side logging.
/l <UserName>Specifies the user name to log on with on the remote computer.
/t {vt100 | vt52 | ansi | vtnt}Specifies the terminal type. Supported terminal types are vt100, vt52, ansi, and vtnt.
<Host> [<Port>]Specifies the hostname or IP address of the remote computer to connect to, and optionally the TCP port to use (default is TCP port 23).
/?Displays help at the command prompt. Alternatively, you can type /h.

Check the listen port

You can use this command for check the connection of a application.

telnet IPADDRESS PORT

telnet 192.168.0.10 80       <- http
telnet 192.168.0.10 25       <- smtp
telnet 192.168.0.10 25 

Check Connection and Close Connection

# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 office-serv ESMTP Sendmail 8.13 ; Mon, 28 Mar 2019 08:00:00 +0900
^]                                 <- Ctrl ]
telnet> quit
Connection closed.

Telnet to Web Server (port 8o or 443

# telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.domain.com (127.0.0.1).
Escape character is '^]'.
GET / HTTP/1.0                       <-  Enter 2 times (http://localhost/index.html)

HTTP/1.1 200 OK
Date: Wed, 29 Jul 2009 15:16:50 GMT
Server: Apache/1.3.37 (Unix) mod_fastcgi/2.4.6 mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.4.7 abbr.
Last-Modified: Mon, 05 Feb 2007 11:04:57 GMT
ETag: "1b200-b2c-45c70f59"
Accept-Ranges: bytes
Content-Length: 2860
Connection: close
Content-Type: text/html

<html>
<html>
<title>TEST</title>

abbr.

</body>
</html>
Connection closed by foreign host.
#

Telnet to Mail Server

# telnet localhost 25
Trying 127.0.0.1...
Connected to test-server.test-server (127.0.0.1).
Escape character is '^]'.
220 test-server.example-sec.local ESMTP
helo localhost
250 test-server.example-sec.local
mail from:user01@example-sec.jp
250 ok
rcpt to:user02@example-sec.jp
250 ok
502 unimplemented (#5.5.1)
data
354 go ahead
From: user01@example-sec.jp
To: user02@example-sec.jp
Subject: test
this is test.

.
250 ok 1184072108 qp 20747

502 unimplemented (#5.5.1)
quit
221 test-server.example-sec.local
Connection closed by foreign host.

  C:\>telnet hostname 25
 220 TEST.local Microsoft ESMTP MAIL Service, Version: 7.5. ready at  Thu, 01 Jul 2018 11:11:11 -0500
 helo test
 250 ESXi-DEV-WEB01.local Hello [127.0.0.1]
 mail from:none@none.com
 250 2.1.0 none@none.com….Sender OK
 rcpt to:youremail@domain.com
 250 2.1.5 youremail@domain.com
 data
 354 Start mail input; end with .
 subject:This is a test email
 This is the body of the test email sent via Telnet.
 .
 250 2.6.0  Queued mail for delivery
 quit
 221 2.0.0 TEST.local Service closing transmission channel
 Connection to host lost.