首页 > 系统相关 >linux 测试对方地址通不通

linux 测试对方地址通不通

时间:2022-09-28 09:22:18浏览次数:90  
标签:0.17 101.199 地址 64 telnet linux 97.65 el6 不通

1. ping xxxxx

 

 如没返回就不通

 

2.telnet 172.25.97.101 8088 或 telnet 172.25.97.101

如果返回telnet: command not found 说明未安装

 

 

解决方法: 安装telnet服务

centos、ubuntu安装telnet命令的方法.

    yum list telnet*              列出telnet相关的安装包
    yum install telnet-server          安装telnet服务
    yum install telnet.*           安装telnet客户端
[root@localhost ~]# yum list telnet* 
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.shu.edu.cn
 * updates: mirrors.cn99.com
Available Packages
telnet.x86_64                            1:0.17-48.el6                      base
telnet-server.x86_64                     1:0.17-48.el6                      base
[root@localhost ~]# yum install telnet-server
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.shu.edu.cn
 * updates: mirrors.cn99.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package telnet-server.x86_64 1:0.17-48.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package               Arch           Version                Repository    Size
================================================================================
Installing:
 telnet-server         x86_64         1:0.17-48.el6          base          37 k

Transaction Summary
================================================================================
Install       1 Package(s)

Total download size: 37 k
Installed size: 54 k
Is this ok [y/N]: y
Downloading Packages:
telnet-server-0.17-48.el6.x86_64.rpm                     |  37 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : 1:telnet-server-0.17-48.el6.x86_64                           1/1 
  Verifying  : 1:telnet-server-0.17-48.el6.x86_64                           1/1 

Installed:
  telnet-server.x86_64 1:0.17-48.el6                                            

Complete!
[root@localhost ~]# 
[root@localhost ~]# yum install telnet.*
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.shu.edu.cn
 * updates: mirrors.cn99.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package telnet.x86_64 1:0.17-48.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================
 Package                       Arch                          Version                              Repository                   Size
====================================================================================================================================
Installing:
 telnet                        x86_64                        1:0.17-48.el6                        base                         58 k

Transaction Summary
====================================================================================================================================
Install       1 Package(s)

Total download size: 58 k
Installed size: 109 k
Is this ok [y/N]: y
Downloading Packages:
telnet-0.17-48.el6.x86_64.rpm                                                                                |  58 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 1:telnet-0.17-48.el6.x86_64                                                                                      1/1 
  Verifying  : 1:telnet-0.17-48.el6.x86_64                                                                                      1/1 

Installed:
  telnet.x86_64 1:0.17-48.el6                                                                                                       

Complete!
[root@localhost ~]# 

 

 

测试端口使用telnet IP地址或主机名 端口,使用tcp协议的例如telnet 192.168.0.1 80测试192.168.0.1的80端口

其执行结果有两种:

1. 端口未打开

$ telnet 101.199.97.65 62715
Trying 101.199.97.65...
telnet: connect to address 101.199.97.65: Connection refused

 

此时,命令已退出。

2. 端口已打开

$ telnet 101.199.97.65 62715
Trying 101.199.97.65...
Connected to 101.199.97.65.
Escape character is '^]'.

 

此时命令未退出。
根据提示Escape character is ‘]‘.可知退出字符为’]’(CTRL+])。此时输入其它字符不能使其退出,CTRL+C都不行。输入CTRL+]后会自动执行,进入命令模式:

^]
telnet>

 

此时再运行 quit 才会真正退出。

telnet> quit
Connection closed.

 

其中,Escape character可以自定义,使用参数-e:

$ telnet -e p 101.199.97.65 62715   #使用p字符
Telnet escape character is 'p'.
Trying 101.199.97.65...
Connected to 101.199.97.65.
Escape character is 'p'.
p
telnet> quit
Connection closed.

 

即便如此,退出telnet还是麻烦。那么,更进一步,如果出现在脚本中应该如何(优雅地)退出telnet呢?

方案
其实可以这样:
1. 输出结果后立即退出

$ echo "" | telnet 101.199.97.65 62715

Trying 101.199.97.65...
Connected to 101.199.97.65.
Escape character is '^]'.
Connection closed by foreign host.  #已成功连通端口并自动退出
$ echo "" | telnet 101.199.97.65 62715
Trying 101.199.97.65...
telnet: connect to address 101.199.97.65: Connection refused #端口未开放

 

2. 输出结果后延迟退出
sleep 2使得telnet输出结果后,停留2秒后退出命令模式。

$ sleep 2 | telnet 101.199.97.65 62715

Trying 101.199.97.65...
Connected to 101.199.97.65.
Escape character is '^]'.
Connection closed by foreign host.

使用这种方式可以将标准输出和标准错误重定向到文件中,通过分析文件的内容来判断端口打开状态

标签:0.17,101.199,地址,64,telnet,linux,97.65,el6,不通
From: https://www.cnblogs.com/wjsqqj/p/16736835.html

相关文章

  • Linux指令
    设置环境变量#方法一:手动修改/etc/environment文件,此法为永久修改#方法二:修改~/.bashrc,在行尾添加下面的信息,此法为永久修改exportPATH=$PATH:/home/book#方法一......
  • Linux PM机制
    概述RPM即Runtimepowermanagement的缩写,之Linux提供的一套电源管理框架。核心思想是分而治之的管理思想,将具体的控制策略和控制权力下放到各个驱动。为所有device提供......
  • Linux网络日志分析与流量监控 pdf
    高清扫描版下载链接:https://pan.baidu.com/s/1OG-5_4ebMeQjSUeO_3l-IA点击这里获取提取码 ......
  • Linux新手要了解的十个知识点
    Linux对于有的新手来说,感觉无从下手,或者不知道从哪儿学起?怎么学?针对这些问题,我给大家说说新手学习Linux需要了解的十个知识点。注意大小写Linux是大小写敏感的系......
  • linux服务器部署多个项目:出现启动一个项目另一个项目就挂掉问题
    问题:linux测试环境部署了多个项目,今天新加了一个项目,出现了部署这一个会让原来一个项目挂掉。重新启动了原来的,新的项目有会挂掉。原因:两个项目启动所配置的内存总和超过,l......
  • 3.TCP-IP & Linux 模型简介
    Dearall,  更新一节Linux网络驱动视频——3.TCP-IP&Linux模型简介,下节课开始正式编写driver。  B站链接:https://www.bilibili.com/video/BV1DG4y1s7ad/?vd_......
  • Linux驱动|rtc-hym8563移植笔记
    本文基于瑞芯微rk3568平台,关于该平台快速入手操作,大家可以参考以下文章:《瑞芯微rk356x板子快速上手》0、什么是rtc-hym8563?RTC:实时时钟的缩写是(Real_TimeClock)。RTC......
  • 查看Linux系统日志
    1.各种日志文件位置/var/log/messages:记录Linux内核消息及各种应用程序的公共日志信息/var/log/cron:记录crond计划任务产生的事件信息/var/log/dmesg......
  • LINUX的唐古拉安装
    Linux唐古拉的安装第三方插件的安装MySQL的安装将安装包拷贝到/usr/local/src解压到/usr/local/,并且将目录改成mysql#进入到MySQL的目录下执行如下命令tar-zxvf......
  • Linux 基础命令
    一、ls1、ls:列出当前目录下的文件和文件夹2、ls-l -l(list):以较详细的列表形式列出当前目录下的文件和文件夹在Linux中ll是ls-l的别名,别名相当于windo......