telnet (TELNET协议的用户界面)

rose1 发表于 2020-07-27 16:11
浏览次数:
在手机上阅读

telnet程序是TELNET协议的用户界面。

查看英文版

目录

1 telnet 运行系统环境

2 telnet 说明

3 telnet 语法

4 telnet 例子

telnet 运行系统环境

Linux

telnet 说明

telnet命令用于使用TELNET协议与另一个主机进行交互通信。 它以命令模式开始,在此模式下将打印telnet命令提示符(“ telnet>”)。

如果使用主机参数调用telnet,它将隐式执行打开命令(有关详细信息,请参见下面的“命令”部分)。

The telnet command is used for interactive communication with another host using the TELNET protocol. It begins in command mode, where it prints a telnet command prompt ("telnet>").

If telnet is invoked with a host argument, it performs an open command implicitly (see the Commands section below for details).

查看英文版

查看中文版

telnet 语法

telnet [-468ELadr] [-S tos] [-b address] [-e escapechar] [-l user] 
       [-n tracefile] [host [port]]

选件

-4 强制IPv4地址解析。
-6 强制进行IPv6地址解析。
-8 请求8位操作。此选项导致尝试协商输入和输出的TELNET BINARY选项。默认情况下,telnet不是“ 8位纯净”的(它不能识别Unicode等8位字符编码)。
-E 禁用转义 字符功能;即,将转义字符设置为“无字符”。
-L 指定输出的8位数据路径。此选项使TELNET BINARY选项在输出上协商。
-a 尝试自动登录。当前,如果远程系统支持,它将通过ENVIRON选项的USER变量发送用户名。通过getlogin系统调用检索用户名。
-b address 在本地套接字上使用bind将其绑定到特定的本地地址。
-d 将调试切换的初始值设置为TRUE。
-r 模拟rlogin。在此模式下,默认的转义字符为tilde。同样,转义字符的解释也发生了变化:转义字符后跟一个点使telnet与远程主机断开连接。甲^ Z(控制-Z),而不是一个点,挂起远程登录,以及^] (控制关闭托架,所述默认的telnet转义字符)生成一个正常的telnet提示。这些代码仅在行首被接受。
-S tos 将telnet连接的IP TOS(服务类型)选项设置为tos值。
-e escapechar 设置转义字符为escapechar。如果未提供任何字符,则将不使用任何转义字符。在连接时输入转义字符会使telnet进入命令模式。
-l user 指定user作为要在远程系统上登录的用户。通过发送指定的名称作为USER 环境变量,因此它要求远程系统支持TELNET ENVIRON选项。此选项暗含-a选项,也可以与open命令一起使用。
-n tracefile 打开跟踪文件以记录跟踪信息。请参阅下面的set tracefile命令。
host 指定要通过网络联系的主机。
port 指定要联系的端口号或服务名称。如果未指定,则使用telnet端口(23)。

协议

打开连接后,telnet将尝试启用TELNET LINEMODE选项。如果失败,则telnet将恢复为两种输入模式之一:“一次输入字符”或“逐行删除”,具体取决于远程系统支持的模式。

当LINEMODE启用,字符处理在本地系统上完成的,远程系统的控制下。当要禁用输入编辑或字符回显时,远程系统将中继该信息。远程系统还将中继对远程系统上发生的任何特殊字符的更改,以便它们可以在本地系统上生效。

在“一次字符”模式下,大多数键入的文本会立即发送到远程主机进行处理。

在“逐行旧模式”模式下,所有文本都在本地回显,并且(通常)仅将完成的行发送到远程主机。“本地回显字符”(最初为“ ^ E ”)可用于关闭和打开本地回显(这通常用于输入密码而不回显密码)。

如果启用了LINEMODE选项,或者localchars切换为TRUE(默认为“逐行”;请参见下文),则用户的quit,intr和flush字符将被本地捕获,并作为TELNET协议序列发送到偏远的一面。如果已启用LINEMODE,则用户的susp和eof也将作为TELNET协议序列发送,而退出将作为TELNET ABORT而不是BREAK发送。有一些选项(请参阅切换自动刷新和切换自动同步,如下所示),这会导致此操作刷新后续的输出到终端(直到远程主机确认TELNET序列)并刷新先前的终端输入(在quit和intr的情况下)。

指令

以下telnet命令可用。唯一前缀被理解为缩写。

auth argument ...

auth命令控制TELNET AUTHENTICATE协议选项。 如果telnet是在未经身份验证的情况下编译的,则将不支持auth命令。 有效参数如下:

disable type 禁用指定的身份验证类型。要获取可用类型的列表,请使用auth disable?命令。
enable type 启用指定的身份验证类型。要获取可用类型的列表,请使用auth enable?命令。
status 列出各种身份验证的当前状态。
请注意,当前版本的telnet不支持身份验证。
close 关闭与远程主机的连接(如果有),然后返回命令模式。
display argument ... 显示全部或部分设置和切换值(请参见下文)。
encrypt argument ...

crypto命令控制TELNET ENCRYPT协议选项。 如果telnet是在未加密的情况下编译的,则将不支持加密命令。

有效参数如下:

disable type [input|output] 禁用指定的加密类型。如果您未指定input或output,那么将禁用两者的加密。要获取可用类型的列表,请使用“ encrypt disable? ”。
enable type [input|output] 启用指定的加密类型。如果您未指定input或output,那么将同时启用两者的加密。要获取可用类型的列表,请使用“ encrypt enable? ”。
input 该参数与“ encrypt start input ”相同。
-input 此参数与“ 加密停止输入 ”相同。
output 该参数与“ encrypt start output ”相同。
-output 此参数与“ 加密停止输出 ”相同。
start [input|output] 尝试开始加密。如果未指定input或output,那么将开始对输入和输出进行加密。
status 显示加密模块的当前状态。
stop [input|output] 停止加密。如果您未指定input或output,那么两者的加密都会停止。
type type 设置默认的加密类型,以供以后的“ encrypt start ”或“ encrypt stop ”命令使用。
请注意,当前版本的telnet不支持加密。
environ arguments...

该ENVIRON命令用于跨越繁殖的环境变量的telnet使用链路TELNET ENVIRON协议选项。从外壳导出的所有变量均已定义,但默认情况下仅将DISPLAY和PRINTER变量标记为要发送。在USER变量被标记,如果要被发送-a或-l 命令行中使用的选项。

environ命令的有效参数为:

define variable value 将变量定义为具有value的值。该命令定义的任何变量都将自动标记为传播(“导出”)。该值可以用单引号或双引号引起来,以便可以包含制表符和空格。
undefine variable 删除任何现有的variable定义。
export variable 标记指定的变量以传播到远程主机。
unexport variable 不要将指定的变量标记为传播到远程主机。远程主机可能仍会明确要求未导出的变量。
list 列出当前的环境变量集。标有星号(“ * ”)的标记将传播到远程主机。远程主机可能仍会明确要求其余部分。
? 打印出environ命令的帮助信息。
logout 将TELNET LOGOUT协议选项发送到远程主机。该命令类似于关闭命令。如果远程主机不支持LOGOUT选项,则什么都不会发生。但是,如果这样做,则该命令应导致它关闭连接。如果远程端也支持挂起用户会话以供以后重新连接的概念,则注销命令指示该会话应立即终止。
mode type

该类型是几个选项之一,这取决于会议的状态。telnet要求远程主机进入请求的模式。如果远程主机说可以,则该模式生效。类型选项如下:

character 禁用TELNET LINEMODE选项,或者,如果对端不了解LINEMODE选项,则输入“一次输入字符”模式。
line 启用TELNET LINEMODE选项,或者,如果远端不了解LINEMODE选项,则尝试进入“逐行老模式”模式。
isig (-isig) 尝试启用(禁用)LINEMODE选项的TRAPSIG模式。这要求启用LINEMODE选项。
edit (-edit) 尝试启用(禁用)LINEMODE选项的EDIT模式。这要求启用LINEMODE选项。
softtabs (-softtabs) 尝试启用(禁用)LINEMODE选项的SOFT_TAB模式。这要求启用LINEMODE选项。
litecho (-litecho) 尝试启用(禁用)LINEMODE选项的LIT_ECHO模式。这要求启用LINEMODE选项。
? 打印出有关mode命令的帮助信息。
open host [[-l] user][- port]

打开与命名主机的连接。如果未指定端口号,则telnet将尝试在标准端口(23)上联系telnet 守护程序。该主机规格可以是主机名或IP地址。该-l选项可用于指定用户名传递到远程系统,如-l命令行选项。

当连接到telnet端口以外的端口时,telnet不会尝试telnet协议协商。这种连接方法使连接到不支持telnet协议的服务成为可能。可以通过在端口号前加一个破折号来强制协议协商。

建立连接后,将按该顺序执行/ etc / telnetrc中与远程主机关联的所有命令以及用户的.telnetrc文件。

telnetrc文件的格式如下:以#开头的行和空白行被视为注释(忽略)。该文件的其余部分应由主机名和要用于该主机的telnet命令序列组成。命令应该每行一个,以空格缩进;以空格开头的行将被解释为主机名。以特殊主机名“ DEFAULT ” 开头的行将适用于所有主机。主机名(包括“ DEFAULT ”)后可以紧跟冒号,端口号或字符串。如果指定了端口,则它必须与命令行上指定的端口完全匹配。如果在命令行上未指定端口,则值'使用telnet '。连接到特定主机后,将执行与该主机关联的命令。

quit 关闭任何打开的会话并退出telnet。一个的文件端上输入状态下,当在命令模式中,将触发该操作为好。
send arguments

将一个或多个特殊的telnet协议字符序列发送到远程主机。以下是可以指定的代码(在一个命令中可以使用多个代码):

abort 发送TELNET ABORT(中止过程)序列。
ao 发送TELNET AO(中止输出)序列,这将导致远程系统将所有输出从远程系统刷新到用户终端。
ayt 发送TELNET AYT(您在吗?)序列,远程系统可能会选择也可能不会选择响应。
brk 发送TELNET BRK(中断)序列,这可能对远程系统有意义。
ec 发送TELNET EC(擦除字符)序列,这将导致远程系统擦除最后输入的字符。
el 发送TELNET EL(擦除线路)序列,这将导致远程系统擦除当前输入的线路。
eof 发送TELNET EOF(文件结束)序列。
eor 发送TELNET EOR(记录结束)序列。
escape 发送当前的telnet转义字符。
ga 发送TELNET GA(继续)序列,这可能对远程系统没有意义。
getstatus 如果远程端支持TELNET STATUS命令,则getstatus将发送子协商以请求服务器发送其当前选项状态。
ip 发送TELNET IP(中断[进程])序列,这将导致远程系统中止当前正在运行的进程。
nop 发送TELNET NOP(无操作)序列。
susp 发送TELNET SUSP(挂起过程)序列。
synch 发送TELNET SYNCH序列。此序列使远程系统放弃所有先前键入(但尚未读取)的输入。此序列作为TCP紧急数据发送(如果远程系统是4.2 BSD系统,则可能不起作用-如果它不起作用,则可能在终端上回显小写的“ r ” )。
do cmd 发送TELNET DO cmd序列。的CMD可以是十进制之间号码0和255为特定的一个符号名,或TELNET命令。该cmd也可以是帮助或?打印出帮助信息,包括已知符号名称的列表。
dont cmd, will cmd, wont cmd 执行类似的操作。
? 打印出send命令的帮助信息。
set argument value, unset argument value

该组命令将设置的telnet变量为特定的值或作为中任一项TRUE。特殊值off关闭与变量关联的功能。此命令等效于使用unset命令。在未设置命令将禁用或设置为FALSE的任何特定变量。可以使用display命令查询变量的值。此处列出了可以设置或未设置但不能切换的变量。另外,toggle命令的任何变量都可以显式设置或取消设置。

ayt 如果telnet处于localchars模式,或者启用了LINEMODE,并且键入了状态字符,则会将TELNET AYT序列发送到远程主机。“ Are You There”字符的初始值是终端的状态字符。
echo 此变量是值(最初为“ ^ E ”),当处于“逐行”模式时,该值在输入的字符进行本地回显(用于正常处理)和抑制输入的字符回显(用于输入例如,密码)。
eof 如果telnet在LINEMODE或“逐行”模式下运行,则将此字符作为一行的第一个字符输入将导致该字符发送到远程系统。eof字符的初始值被视为终端的eof字符。
erase 如果telnet处于localchars模式(请参阅下面的切换localchars),并且如果telnet在“一次字符”模式下运行,则键入此字符时,会将TELNET EC序列(请参见上面的send ec)发送到远程系统。擦除字符的初始值被视为终端的擦除字符。
escape 此变量是telnet转义字符(最初为“ ^ [ ”),它会导致进入telnet命令模式(连接到远程系统时)。
flushoutput 如果telnet处于localchars模式(请参阅下面的切换localchars),并且键入了flushoutput字符,则TELNET AO序列(请参见上面的send ao)将发送到远程主机。刷新字符的初始值被视为终端的刷新字符。
forw1forw2 如果telnet在LINEMODE中运行,则这些字符在键入时会导致部分行转发到远程系统。转发字符的初始值取自终端的eol和eol2字符。
interrupt 如果telnet处于localchars模式(请参阅下面的切换localchars),并且键入了中断字符,则会将TELNET IP序列(请参见上面的send ip)发送到远程主机。中断字符的初始值被视为终端的intr字符。
kill 如果telnet处于localchars模式(请参阅下面的切换localchars),并且如果telnet处于“一次字符”模式下,则在键入此字符时,会将TELNET EL序列(请参见上面的send el)发送到远程系统。用于杀字符的初始值取为终端的杀字符。
lnext 如果telnet在LINEMODE或“逐行”模式下运行,则此字符被视为终端的下一个字符。下一个字符的初始值被视为终端的下一个字符。
quit 如果telnet处于localchars模式(请参阅下面的切换localchars),并且键入了退出字符,则TELNET BRK序列(请参见上面的send brk)将发送到远程主机。退出字符的初始值被视为终端的退出字符。
reprint 如果telnet在LINEMODE或“逐行”模式下运行,则该字符被视为终端的重印字符。重印字符的初始值被视为终端的重印字符。
rlogin 此变量是rlogin模式转义字符。设置它会启用rlogin模式,与r命令行选项一样(请参见上文)。
start 如果启用了TELNET TOGGLE-FLOW-CONTROL选项,那么该字符将被视为终端的起始字符。为初始值杀字符被取为终端的开始字符。
stop 如果启用了TELNET TOGGLE-FLOW-CONTROL选项,那么该字符将被视为终端的停止字符。杀死字符的初始值被视为终端的终止字符。
susp 如果telnet处于localchars模式,或者启用了LINEMODE,并且键入了暂停字符,则TELNET SUSP序列(请参见上面的send susp)将发送到远程主机。暂挂字符的初始值被视为终端的暂挂字符。
tracefile 此变量是将写入由netdata或选项跟踪为TRUE导致的输出的文件。如果将其设置为“ - ”,则跟踪信息将被写入标准输出(这是默认设置)。
worderase 如果telnet在LINEMODE或“逐行旧模式”模式下运行,则此字符将被视为终端的文字字符。文字字符的初始值被认为是终端的文字字符。
? 显示合法的set(或unset)命令。
slc state

该SLC的命令(设置本地字符)用于设置或更改时,特殊字符的状态TELNET LINEMODE启用选项。特殊字符是映射到TELNET命令序列的字符(例如ip或quit)或行编辑字符(例如delete和kill)。默认情况下,将导出本地特殊字符。

状态可能是以下之一:

check 验证当前设置的当前特殊字符。要求远端发送所有当前的特殊字符设置,如果与本地有任何差异,则本地将切换到远程值。
export 切换到特殊字符的本地默认值。本地默认字符是启动telnet时本地终端的字符。
import 切换到特殊字符的远程默认值。远程默认字符是建立TELNET连接时远程系统的默认字符。
? 打印出slc命令的帮助信息。
status 显示telnet的当前状态。此命令包括远程主机的名称(如果有)以及当前模式。
toggle arguments ...

切换(在TRUE和FALSE之间)控制telnet如何响应事件的各种标志。可以使用set和unset命令将这些标志显式设置为TRUE或FALSE。一次可以切换多个标志。这些标志的状态可以用display命令检查。有效标志是:

authdebug 打开身份验证代码的调试。仅当启用身份验证支持时,此标志才存在。
autoflush 如果autoflush和localchars均为TRUE,则当ao或quit字符被识别(并转换为TELNET序列;有关详细信息,请参见上面的设置)时,telnet拒绝在用户终端上显示任何数据,直到远程系统确认为止(通过a TELNET TIMING MARK选项),它已经处理了那些TELNET序列。如果终端用户未执行“ stty noflsh ”,则此切换的初始值为TRUE,否则为FALSE(请参见stty)。
autoencryptautodecrypt 当TELNET ENCRYPT选项协商,默认情况下,数据流的实际的加密(或解密)不会自动启动。所述autoencrypt(或autodecrypt,输出(输入)流的加密应尽快被启用)命令的状态。

请注意,只有启用了加密支持,此标志才存在。
autologin 如果远程支持TELNET AUTHENTICATION选项,则telnet尝试使用它来执行自动身份验证。如果不支持TELNET AUTHENTICATION选项,则使用TELNET ENVIRON选项传播用户的登录名。设置此标志与在打开命令或命令行上指定“ a”选项相同。
autosynch 如果autosynch和localchars都是TRUE,则当或者INTR或退出字符键入(见设置为的以上描述INTR和退出字符),将所得的telnet顺序发送之后是TELNET SYNCH序列。此过程应使远程系统开始丢弃所有先前键入的输入,直到已读取并执行了两个telnet序列为止。此切换的初始值为FALSE。
binary 在输入和输出上启用或禁用TELNET BINARY选项。
inbinary 在输入上启用或禁用TELNET BINARY选项。
outbinary 在输出上启用或禁用TELNET BINARY选项。
crlf 如果为TRUE,则回车将作为CR LF发送。如果为FALSE,则回车将作为CR NUL发送。此切换的初始值为FALSE。
crmod 切换回车模式。启用此模式后,将从远程主机收到的大多数回车符将映射为回车符,然后换行。此模式不影响用户键入的那些字符,仅影响从远程主机接收到的那些字符。除非远程主机仅发送回车符,而不发送换行符,否则该模式不是很有用。此切换的初始值为FALSE。
debug 切换套接字级别调试(仅对超级用户有用)。此切换的初始值为FALSE。
encdebug 打开加密代码的调试信息。请注意,仅当加密支持可用时,此标志才存在。
localchars 如果为TRUE,则将在本地识别flush,interrupt,quit,ease和kill字符(请参见上面的设置),并将其转换为(希望)适当的TELNET控制序列(分别为ao,ip,brk,ec和el;请参阅上面的发送)。此切换的初始值在“逐行显示”模式下为TRUE,在“每次输入字符”模式下为FALSE。当LINEMODE选项启用,价值localchars被忽略,并假定始终为TRUE。如果LINEMODE曾经被启用,那么quit将作为abort和eof发送,并且作为eof和susp发送;请参阅上面的发送)。
netdata 切换所有网络数据的显示(十六进制格式)。此切换的初始值为FALSE。
options 切换某些内部telnet协议处理的显示(与telnet选项有关)。此切换的初始值为FALSE。
prettydump 当netdata启用触发器,如果prettydump启用从输出netdata命令将被在一个以上用户可读格式格式化。在输出中的每个字符之间放置空格,并且telnet转义序列的开头以星号(“ * ”)开头,以帮助查找它们。
skiprc 当skiprc切换为TRUE时,telnet不会读取telnetrc文件。此切换的初始值为FALSE。
termdata 切换所有终端数据的显示(十六进制格式)。此切换的初始值为FALSE。
verbose_encrypt 当verbose_encrypt切换为TRUE时,每次启用或禁用加密时,TELNET都会输出一条消息。此切换的初始值为FALSE。仅当加密支持可用时,此标志才存在。
? 显示合法的切换命令。
z 暂停telnet。该命令仅在用户使用C Shell(csh)时有效。
! [command] 在本地系统的子shell中执行单个命令。如果省略command,则将调用交互式子shell。
? [command] 得到帮助。telnet不带任何参数,将显示帮助摘要。如果指定了命令,则telnet将打印该命令的帮助信息。

环境

telnet至少使用HOME,SHELL,DISPLAY和TERM 环境变量。其他环境变量可以通过TELNET ENVIRON选项传播到另一端。

档案

/etc/telnetrc 全局telnet启动值
~/.telnetrc 用户自定义的telnet启动值
telnet [-468ELadr] [-S tos] [-b address] [-e escapechar] [-l user] 
       [-n tracefile] [host [port]]

Options

-4 Force IPv4 address resolution.
-6 Force IPv6 address resolution.
-8 Request 8-bit operation. This option causes an attempt to negotiate the TELNET BINARY option for both input and output. By default, telnet is not "8-bit clean" (it does not recognize 8-bit character encodings such as Unicode).
-E Disables the escape character functionality; that is, sets the escape character to "no character".
-L Specifies an 8-bit data path on output. This option causes the TELNET BINARY option to be negotiated on output.
-a Attempt automatic login. Currently, this sends the username via the USER variable of the ENVIRON option if supported by the remote system. The username is retrieved via the getlogin system call.
-b address Use bind on the local socket to bind it to a specific local address.
-d Sets the initial value of the debug toggle to TRUE.
-r Emulate rlogin. In this mode, the default escape character is a tilde. Also, the interpretation of the escape character is changed: an escape character followed by a dot causes telnet to disconnect from the remote host. A ^Z (Control-Z) instead of a dot suspends telnet, and a ^] (Control-close bracket, the default telnet escape character) generates a normal telnet prompt. These codes are accepted only at the beginning of a line.
-S tos Sets the IP TOS (type-of-service) option for the telnet connection to the value tos.
-e escapechar Sets the escape character to escapechar. If no character is supplied, no escape character will be used. Entering the escape character while connected causes telnet to drop to command mode.
-l user Specify user as the user to log in as on the remote system. By sending the specified name as the USER environment variable, so it requires that the remote system support the TELNET ENVIRON option. This option implies the -a option, and may also be used with the open command.
-n tracefile Opens tracefile for recording trace information. See the set tracefile command below.
host Specifies a host to contact over the network.
port Specifies a port number or service name to contact. If not specified, the telnet port (23) is used.

Protocol

Once a connection is opened, telnet will attempt to enable the TELNET LINEMODE option. If this fails, then telnet will revert to one of two input modes: either "character at a time" or "old line by line" depending on what the remote system supports.

When LINEMODE is enabled, character processing is done on the local system, under the control of the remote system. When input editing or character echoing is to be disabled, the remote system will relay that information. The remote system will also relay changes to any special characters that happen on the remote system, so that they can take effect on the local system.

In "character at a time" mode, most text typed is immediately sent to the remote host for processing.

In "old line by line" mode, all text is echoed locally, and (normally) only completed lines are sent to the remote host. The "local echo character" (initially "^E") may be used to turn off and on the local echo (this would mostly be used to enter passwords without the password being echoed).

If the LINEMODE option is enabled, or if the localchars toggle is TRUE (the default for "old line by line"; see below), the user's quitintr, and flush characters are trapped locally, and sent as TELNET protocol sequences to the remote side. If LINEMODE has ever been enabled, then the user's susp and eof are also sent as TELNET protocol sequences, and quit is sent as a TELNET ABORT instead of BREAK. There are options (see toggle autoflush and toggle autosynch, below) which cause this action to flush subsequent output to the terminal (until the remote host acknowledges the TELNET sequence) and flush previous terminal input (in the case of quit and intr).

Commands

The following telnet commands are available. Unique prefixes are understood as abbreviations.

auth argument ...

The auth command controls the TELNET AUTHENTICATE protocol option. If telnet was compiled without authentication, the auth command will not be supported. Valid arguments are as follows:

disable type Disable the specified type of authentication. To obtain a list of available types, use the auth disable ? command.
enable type Enable the specified type of authentication. To obtain a list of available types, use the auth enable ? command.
status List the current status of the various types of authentication.
Note that the current version of telnet does not support authentication.
close Close the connection to the remote host, if any, and return to command mode.
display argument ... Display all, or some, of the set and toggle values (see below).
encrypt argument ...

The encrypt command controls the TELNET ENCRYPT protocol option. If telnet was compiled without encryption, the encrypt command will not be supported.

Valid arguments are as follows:

disable type [input|output] Disable the specified type of encryption. If you do not specify input or output, encryption of both is disabled. To obtain a list of available types, use "encrypt disable ?".
enable type [input|output] Enable the specified type of encryption. If you do not specify input or output, encryption of both is enabled. To obtain a list of available types, use "encrypt enable ?".
input This argument is the same as "encrypt start input".
-input This argument is the same as "encrypt stop input".
output This argument is the same as "encrypt start output".
-output This argument is the same as "encrypt stop output".
start [input|output] Attempt to begin encrypting. If you do not specify input or output, encryption of both input and output is started.
status Display the current status of the encryption module.
stop [input|output] Stop encrypting. If you do not specify input or output, encryption of both is stopped.
type type Sets the default type of encryption to be used with later "encrypt start" or "encrypt stop" commands.
Note that the current version of telnet does not support encryption.
environ arguments...

The environ command is used to propagate environment variables across the telnet link using the TELNET ENVIRON protocol option. All variables exported from the shell are defined, but only the DISPLAY and PRINTER variables are marked to be sent by default. The USER variable is marked to be sent if the -a or -l command-line options were used.

Valid arguments for the environ command are:

define variable value Define the variable to have a value of value. Any variables defined by this command are automatically marked for propagation ("exported"). The value may be enclosed in single or double quotes so that tabs and spaces may be included.
undefine variable Remove any existing definition of variable.
export variable Mark the specified variable for propagation to the remote host.
unexport variable Do not mark the specified variable for propagation to the remote host. The remote host may still ask explicitly for variables that are not exported.
list List the current set of environment variables. Those marked with an asterisk ("*") will be propagated to the remote host. The remote host may still ask explicitly for the rest.
? Prints out help information for the environ command.
logout Send the TELNET LOGOUT protocol option to the remote host. This command is similar to a close command. If the remote host does not support the LOGOUT option, nothing happens. But if it does, this command should cause it to close the connection. If the remote side also supports the concept of suspending a user's session for later reattachment, the logout command indicates that the session should be terminated immediately.
mode type

The type is one of several options, depending on the state of the session. telnet asks the remote host to go into the requested mode. If the remote host says it can, that mode takes effect. Options for type are as follows:

character Disable the TELNET LINEMODE option, or, if the remote side does not understand the LINEMODE option, then enter "character at a time" mode.
line Enable the TELNET LINEMODE option, or, if the remote side does not understand the LINEMODE option, then attempt to enter "old-line-by-line" mode.
isig (-isig) Attempt to enable (disable) the TRAPSIG mode of the LINEMODE option. This requires that the LINEMODE option be enabled.
edit (-edit) Attempt to enable (disable) the EDIT mode of the LINEMODE option. This requires that the LINEMODE option be enabled.
softtabs (-softtabs) Attempt to enable (disable) the SOFT_TAB mode of the LINEMODE option. This requires that the LINEMODE option be enabled.
litecho (-litecho) Attempt to enable (disable) the LIT_ECHO mode of the LINEMODE option. This requires that the LINEMODE option be enabled.
? Prints out help information for the mode command.
open host [[-l] user][- port]

Open a connection to the named host. If no port number is specified, telnet will attempt to contact a telnet daemon at the standard port (23). The host specification may be a hostname or IP address. The -l option may be used to specify a username to be passed to the remote system, like the -l command-line option.

When connecting to ports other than the telnet port, telnet does not attempt telnet protocol negotiations. This method of connecting makes it possible to connect to services that do not support the telnet protocol without making a mess. Protocol negotiation can be forced by placing a dash before the port number.

After establishing a connection, any commands associated with the remote host in /etc/telnetrc and the user's .telnetrc file are executed, in that order.

The format of the telnetrc files is as follows: Lines beginning with a #, and blank lines, are treated as comments (ignored). The rest of the file should consist of hostnames and sequences of telnet commands to use with that host. Commands should be one per line, indented by whitespace; lines beginning without whitespace are interpreted as hostnames. Lines beginning with the special hostname ‘DEFAULT’ will apply to all hosts. Hostnames including ‘DEFAULT’ may be followed immediately by a colon and a port number or string. If a port is specified it must match exactly with what is specified on the command line. If no port was specified on the command line, then the value ‘telnet’ is used. Upon connecting to a particular host, the commands associated with that host are executed.

quit Close any open session and exit telnet. An end of file condition on input, when in command mode, will trigger this operation as well.
send arguments

Send one or more special telnet protocol character sequences to the remote host. The following are the codes which may be specified (more than one may be used in one command):

abort Sends the TELNET ABORT (abort processes) sequence.
ao Sends the TELNET AO (abort output) sequence, which should cause the remote system to flush all output from the remote system to the user's terminal.
ayt Sends the TELNET AYT (are you there?) sequence, to which the remote system may or may not choose to respond.
brk Sends the TELNET BRK (break) sequence, which may have significance to the remote system.
ec Sends the TELNET EC (erase character) sequence, which should cause the remote system to erase the last character entered.
el Sends the TELNET EL (erase line) sequence, which should cause the remote system to erase the line currently being entered.
eof Sends the TELNET EOF (end-of-file) sequence.
eor Sends the TELNET EOR (end-of-record) sequence.
escape Sends the current telnet escape character.
ga Sends the TELNET GA (go ahead) sequence, which likely has no significance to the remote system.
getstatus If the remote side supports the TELNET STATUS command, getstatus will send the subnegotiation to request that the server send its current option status.
ip Sends the TELNET IP (interrupt [rocess) sequence, which should cause the remote system to abort the currently running process.
nop Sends the TELNET NOP (no operation) sequence.
susp Sends the TELNET SUSP (duspend process) sequence.
synch Sends the TELNET SYNCH sequence. This sequence causes the remote system to discard all previously typed (but not yet read) input. This sequence is sent as TCP urgent data (and may not work if the remote system is a 4.2 BSD system -- if it doesn't work, a lowercase "r" may be echoed on the terminal).
do cmd Sends the TELNET DO cmd sequence. The cmd can be either a decimal number between 0 and 255, or a symbolic name for a specific TELNET command. The cmd can also be either help or ? to print out help information, including a list of known symbolic names.
dont cmd, will cmd, wont cmd Similar to do.
? Prints out help information for the send command.
set argument value, unset argument value

The set command will set any one of the telnet variables to a specific value or as TRUE. The special value off turns off the function associated with the variable. This command is equivalent to using the unset command. The unset command will disable or set to FALSE any of the specified variables. The values of variables may be interrogated with the display command. The variables which may be set or unset, but not toggled, are listed here. Also, any of the variables for the toggle command may be explicitly set or unset.

ayt If telnet is in localchars mode, or LINEMODE is enabled, and the status character is typed, a TELNET AYT sequence is sent to the remote host. The initial value for the "Are You There" character is the terminal's status character.
echo This variable is the value (initially "^E") which, when in "line by line" mode, toggles between doing local echoing of entered characters (for normal processing), and suppressing echoing of entered characters (for entering, say, a password).
eof If telnet is operating in LINEMODE or "old line by line" mode, entering this character as the first character on a line will cause this character to be sent to the remote system. The initial value of the eof character is taken to be the terminal's eof character.
erase If telnet is in localchars mode (see toggle localchars below), and if telnet is operating in "character at a time" mode, then when this character is typed, a TELNET EC sequence (see send ec above) is sent to the remote system. The initial value for the erase character is taken to be the terminal's erase character.
escape This variable is the telnet escape character (initially "^[") which causes entry into telnet command mode (when connected to a remote system).
flushoutput If telnet is in localchars mode (see toggle localchars below) and the flushoutput character is typed, a TELNET AO sequence (see send ao above) is sent to the remote host. The initial value for the flush character is taken to be the terminal's flush character.
forw1forw2 If telnet is operating in LINEMODE, these are the characters that, when typed, cause partial lines to be forwarded to the remote system. The initial value for the forwarding characters are taken from the terminal's eol and eol2 characters.
interrupt If telnet is in localchars mode (see toggle localchars below) and the interrupt character is typed, a TELNET IP sequence (see send ip above) is sent to the remote host. The initial value for the interrupt character is taken to be the terminal's intr character.
kill If telnet is in localchars mode (see toggle localchars below), and if telnet is operating in "character at a time" mode, then when this character is typed, a TELNET EL sequence (see send el above) is sent to the remote system. The initial value for the kill character is taken to be the terminal's kill character.
lnext If telnet is operating in LINEMODE or "old line by line" mode, then this character is taken to be the terminal's lnext character. The initial value for the lnext character is taken to be the terminal's lnext character.
quit If telnet is in localchars mode (see toggle localchars below) and the quit character is typed, a TELNET BRK sequence (see send brk above) is sent to the remote host. The initial value for the quit character is taken to be the terminal's quit character.
reprint If telnet is operating in LINEMODE or "old line by line" mode, then this character is taken to be the terminal's reprint character. The initial value for the reprint character is taken to be the terminal's reprint character.
rlogin This variable is the rlogin mode escape character. Setting it enables rlogin mode, as with the r command-line option (see above).
start If the TELNET TOGGLE-FLOW-CONTROL option is enabled, then this character is taken to be the terminal's start character. The initial value for the kill character is taken to be the terminal's start character.
stop If the TELNET TOGGLE-FLOW-CONTROL option is enabled, then this character is taken to be the terminal's stop character. The initial value for the kill character is taken to be the terminal's stop character.
susp If telnet is in localchars mode, or LINEMODE is enabled, and the suspend character is typed, a TELNET SUSP sequence (see send susp above) is sent to the remote host. The initial value for the suspend character is taken to be the terminal's suspend character.
tracefile This variable is the file to which the output, caused by netdata or option tracing being TRUE, will be written. If it is set to "-", then tracing information will be written to standard output (this is the default).
worderase If telnet is operating in LINEMODE or "old line by line" mode, then this character is taken to be the terminal's worderase character. The initial value for the worderase character is taken to be the terminal's worderase character.
? Displays the legal set (or unset) commands.
slc state

The slc command (set local characters) is used to set or change the state of the special characters when the TELNET LINEMODE option is enabled. Special characters are characters that get mapped to TELNET commands sequences (like ip or quit) or line editing characters (like erase and kill). By default, the local special characters are exported.

state may be one of the following:

check Verify the current settings for the current special characters. The remote side is requested to send all the current special character settings, and if there are any discrepancies with the local side, the local side will switch to the remote value.
export Switch to the local defaults for the special characters. The local default characters are those of the local terminal at the time when telnet was started.
import Switch to the remote defaults for the special characters. The remote default characters are those of the remote system at the time when the TELNET connection was established.
? Prints out help information for the slc command.
status Show the current status of telnet. This command includes the name of the remote host, if any, as well as the current mode.
toggle arguments ...

Toggle (between TRUE and FALSE) various flags that control how telnet responds to events. These flags may be set explicitly to TRUE or FALSE using the set and unset commands. More than one flag may be toggled at once. The state of these flags may be examined with the display command. Valid flags are:

authdebug Turns on debugging for the authentication code. This flag only exists if authentication support is enabled.
autoflush If autoflush and localchars are both TRUE, then when the ao, or quit characters are recognized (and transformed into TELNET sequences; see set above for details), telnet refuses to display any data on the user's terminal until the remote system acknowledges (via a TELNET TIMING MARK option) that it has processed those TELNET sequences. The initial value for this toggle is TRUE if the terminal user had not done an "stty noflsh", otherwise FALSE (see stty).
autoencryptautodecrypt When the TELNET ENCRYPT option is negotiated, by default the actual encryption (or decryption) of the data stream does not start automatically. The autoencrypt (or autodecrypt) command states that encryption of the output (input) stream should be enabled as soon as possible.

Note that this flag exists only if encryption support is enabled.
autologin If the remote side supports the TELNET AUTHENTICATION option, telnet attempts to use it to perform automatic authentication. If the TELNET AUTHENTICATION option is not supported, the user's login name is propagated using the TELNET ENVIRON option. Setting this flag is the same as specifying the "a" option to the open command or on the command line.
autosynch If autosynch and localchars are both TRUE, then when either the intr or quit characters is typed (see set above for descriptions of the intr and quit characters), the resulting telnet sequence sent is followed by the TELNET SYNCH sequence. This procedure should cause the remote system to begin throwing away all previously typed input until both of the telnet sequences have been read and acted upon. The initial value of this toggle is FALSE.
binary Enable or disable the TELNET BINARY option on both input and output.
inbinary Enable or disable the TELNET BINARY option on input.
outbinary Enable or disable the TELNET BINARY option on output.
crlf If this is TRUE, then carriage returns will be sent as CR LF. If this is FALSE, then carriage returns will be send as CR NUL. The initial value for this toggle is FALSE.
crmod Toggle carriage return mode. When this mode is enabled, most carriage return characters received from the remote host will be mapped into a carriage return followed by a line feed. This mode does not affect those characters typed by the user, only those received from the remote host. This mode is not very useful unless the remote host only sends carriage return, but never line feed. The initial value for this toggle is FALSE.
debug Toggles socket level debugging (useful only to the superuser). The initial value for this toggle is FALSE.
encdebug Turns on debugging information for the encryption code. Note that this flag only exists if encryption support is available.
localchars If this is TRUE, then the flushinterruptquiterase, and kill characters (see set above) are recognized locally, and transformed into (hopefully) appropriate TELNET control sequences (respectively aoipbrkec, and el; see send above). The initial value for this toggle is TRUE in "old line by line" mode, and FALSE in "character at a time" mode. When the LINEMODE option is enabled, the value of localchars is ignored, and assumed to always be TRUE. If LINEMODE has ever been enabled, then quit is sent as abort, and eof and are sent as eof and susp; see send above).
netdata Toggles the display of all network data (in hexadecimal format). The initial value for this toggle is FALSE.
options Toggles the display of some internal telnet protocol processing (having to do with telnet options). The initial value for this toggle is FALSE.
prettydump When the netdata toggle is enabled, if prettydump is enabled the output from the netdata command will be formatted in a more user-readable format. Spaces are put between each character in the output, and the beginning of telnet escape sequences are preceded by an asterisk ("*") to aid in locating them.
skiprc When the skiprc toggle is TRUEtelnet does not read the telnetrc files. The initial value for this toggle is FALSE.
termdata Toggles the display of all terminal data (in hexadecimal format). The initial value for this toggle is FALSE.
verbose_encrypt When the verbose_encrypt toggle is TRUETELNET prints out a message each time encryption is enabled or disabled. The initial value for this toggle is FALSE. This flag only exists if encryption support is available.
? Displays the legal toggle commands.
z Suspend telnet. This command only works when the user is using the C Shell (csh).
! [command] Execute a single command in a subshell on the local system. If command is omitted, then an interactive subshell is invoked.
? [command] Get help. With no arguments, telnet prints a help summary. If a command is specified, telnet will print the help information for that command.

Environment

telnet uses at least the HOMESHELLDISPLAY, and TERM environment variables. Other environment variables may be propagated to the other side via the TELNET ENVIRON option.

Files

/etc/telnetrc global telnet startup values
~/.telnetrc user customized telnet startup values

查看英文版

查看中文版

telnet 例子

telnet myhost.com

尝试打开与远程主机myhost.com的连接。如果建立连接,主机将提示输入登录名和密码。

telnet -l myusername myhost.com 5555

尝试使用登录名myusername在端口5555上打开到远程主机myhost.com的连接。如果成功,主机将提示输入myusername的密码。

telnet

打开本地telnet>提示符,您可以在其中输入上面列出的任何命令。例如,在提示符下输入以下命令:

telnet> open myhost.com

...将尝试打开与myhost.com的连接,如第一个示例所示。

telnet myhost.com

Attempts to open a connection to the remote host myhost.com. If a connection is established, the host will prompt for a login name and password.

telnet -l myusername myhost.com 5555

Attempts to open a connection to the remote host myhost.com on port 5555, using the login name myusername. If successful, the host will prompt for myusername's password.

telnet

Opens a local telnet> prompt, where you can enter any of the commands listed above. For example, entering the following command at the prompt:

telnet> open myhost.com

...will attempt to open a connection to myhost.com, as in our first example.

查看英文版

查看中文版

其他命令行

tabs | tac | talk | tail | tcopy | tty | tar | tbl | tcpdump | tcsh | time | tee | timex | telinit | test | top | touch | tput | tr | troff | traceroute |

如此好文,分享给朋友
发表评论
验证码:
评论列表
共0条