Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the telnet command to test port connectivity

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to use the telnet command to test port connectivity", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use the telnet command to test port connectivity" this article.

The telnet command is usually used for remote login. Telnet program is a remote login client program based on TELNET protocol. Telnet protocol is a member of TCP/IP protocol family, and it is the standard protocol and main way of Internet remote login service.

There are two kinds of execution results: the port is not open $telnet 101.199.97.65 62715Trying 101.199.97.65...telnet: connect to address 101.199.97.65: Connection refused

At this point, the command has exited.

The port is open for $telnet 101.199.97.65 62715Trying 101.199.97.65...Connected to 101.199.97.65.Escape character is'^]'.

The command did not exit at this time. According to the prompt Escape character is'^]'. The exit character is'^]'(CTRL+]). Typing other characters at this time cannot make it exit, not even CTRL+C. After entering CTRL+], it will execute automatically and enter the command mode:

^] telnet >

Running quit at this point will not really exit.

Telnet > quitConnection closed.

Where Escape character can be customized, using the parameter-e:

$telnet-e p 101.199.97.65 62715 # uses the p character Telnet escape character is' p'.Trying 101.199.97.65...Connected to 101.199.97.65.Escape character is' p'.ptelnet > quitConnection closed.

Even so, quitting telnet is troublesome. So, further, how do you (gracefully) exit telnet if it appears in a script?

Scheme

In fact, it can be like this:

Exit immediately after outputting the result

$echo "" | telnet 101.199.97.65 62715Trying 101.199.97.65...Connected to 101.199.97.65.Escape character is'^] '.Connection closed by foreign host. # successfully connected to the port and automatically exited $echo "" | telnet 101.199.97.65 62715Trying 101.199.97.65...telnet: connect to address 101.199.97.65: Connection refused # port is not open

Delay exit after outputting the result

Sleep 2 causes the telnet to output the result, stay for 2 seconds and then exit command mode.

$sleep 2 | telnet 101.199.97.65 62715Trying 101.199.97.65...Connected to 101.199.97.65.Escape character is'^] .Connection closed by foreign host.

In this way, standard output and standard error can be redirected to a file, and the port open status can be determined by analyzing the contents of the file.

The above is all the contents of the article "how to use the telnet command to test port connectivity". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 265

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report