Telnet protocol Content Extraction

Source: Internet
Author: User
Telnet protocol Content Extraction

Option Negotiation is
Telnet
The most complex part of the Protocol.
39
Options are used to configure the working mode between the local and remote hosts. When one party wants to execute an option, it needs to send a request to the other end. If the other party accepts this option, the option takes effect at both ends. Otherwise, the two ends maintain the original mode.
Telnet
Command Format, such as table
2.1
, Table
2.2
.
IAC
Yes
Telnet
Retention code in the agreement, used by both parties
IAC
Determine whether the received bytes are data or commands,
Telnet
The protocol command must contain at least two characters (
IAC
And the command code ).
3
Bytes. The third byte is the negotiated option. When sub-options exist in the negotiated options, sub-option negotiation is required. The command format is as follows:
2.2
.

 

Table 2.

1 Telnet
Option Negotiation Command Format

IAC

Command code

Option Code

Table
2.2 Telnet
Sub-option negotiation Command Format

IAC

Sb

Option Code

Parameters

IAC

Se

 

 

 

The algorithm IDEA is to remove sub-option negotiation and option negotiation, and the rest of the content is the transmitted content. The specific implementation algorithm is to retrieve the storage array text
I
Characters, I
The initial value is 0.
First, Judge text
[I
Whether it is '/0
', If it is'/0
', The extracted content is checked. If not, it is determined whether it is IAC.
, If not IAC
Stores this character. If yes, it determines whether the next character is sb.
, If it is sb
That is, to start sub-option negotiation, you need to repeatedly search for IAC
And se
String until it is found to exit the search, if it is not sb
Determines whether it is "will ".
, Wont
, Do
Or dont
If not, this character is stored. If not, the next character is discarded, because the next character will be the character of the negotiated content, so that Telnet can be completed.
Protocol Analysis and content extraction.



Option Negotiation between Telnet connections

Telnet runs at the application layer based on the TCP transmission protocol and provides terminal interaction between the client and the server.

Telnet uses a TCP connection. Unlike FTP, two TCP connections are used. The port number used by the telnet server is 23.

Both Parties shall negotiate options during Telnet connection.

For example, the size of the window in character mode and the terminal type must be negotiated.

Negotiation is implemented through commands supported by Telnet.

Common Telnet commands (For details, refer to TCP/IP details p303 ):

Se 240 (F0) suboption ended

Start with Sb 250 (FA) sub-option

The first byte negotiated by the IAC 255 (FF) Option

Will 251 (FB) sender activation option (Recipient agrees to activation option)

Do 253 (FD) receiver agrees (sender wants recipient to activate option)

Wont 252 (FC) receiver does not agree

Dont 254 (FE) receiver responds to wont

Code of common Telnet options (For details, refer to TCP/IP details p304 ):

1 (0x01) echo)

3 (0x03) suppress continues (you can select this option to transfer one character at a time)

24 (0x18) terminal type

31 (0x1f) window size

32 (0x20) terminal speed

33 (0x21) remote traffic control

34 (0x22) rows

36 (0x24) Environment Variables

For example, the actual process of establishing a telnet connection is as follows: (192.168.1.11 is the client. 192.168.1.1 is the server)

1) TCP: 192.168.1.11: 49200> 192.168.1.1: 23 [SYN]

2) TCP: 192.168.1.1: 23> 192.168.1.11: 49200 [SYN, ack]

3) TCP: 192.168.1.11: 49200> 192.168.1.1: 23 [ack]

4) telnet: 23> 49200 IAC do 24 (meaning that the receiver can activate the terminal class dynamic command: Do terminal type)

5)
TELNET: 49200> 23 IAC will 24/IAC will 31 (two Commands: IAC will 24 IAC
Will 31 indicates command: Will terminal type/command will negotiate about
Window Size) tells the server to agree to the terminal type and to activate the window size.

6) telnet: 23> 49200 IAC do 31/IAC Sb 18 24 01/IAC Se (Response client allows negotiation window size/sub-option send your terminal type/sub-option to end)

7) telnet: 49200> 23 iac sb 31 80 26/IAC Se (Response server, the size of the sub-option window is 80/26/the sub-option ends)

8) telnet: 49200> 23 IAC Sb 18 "ANSI"/IAC se)

9) telnet: 23> 49200 IAC will 03/IAC will 01 (inform the client to allow the suppression to continue/allow ECHO)

10) telnet: 49200> 23 IAC do 03 (in response to the server, the recipient agrees to allow the suppression to continue)

11) telnet: 49200> 23 IAC do 01 (in response to the server, the receiver agrees to allow ECHO)

12) telnet: Data)

13) telnet: Data)

14) telnet: Data)

15) TCP: 192.168.1.11: 49200> 192.168.1.1: 23 [Fin ack] (request to disconnect)

16) TCP: 192.168.1.1: 23> 192.168.1.11: 49200 [ack]

17) TCP: 192.168.1.1: 23> 192.168.1.11: 49200 [Fin ack] (request to disconnect)

18) TCP: 192.168.1.11: 49200> 192.168.1.1: 23 [ack]

.... Here, some sub-option protocols are skipped. generally, you log on to the host and both parties negotiate on some options. and the recipient agrees or does not agree (do, dont, or will wont)

 

Http://blogold.chinaunix.net/u1/39518/showart_2466512.html


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.