怎么判断linux22端口是否通,判断端口通不通的几种方法
通常使用"telnet ip port"判断端口通不通. 有其它方法吗?先看下面的几种方法
准备环境
启动一个web服务器,提供端口.
[wyq@localhost ~]$ python -m SimpleHTTPServer 8080
Serving HTTP on 0.0.0.0 port 8080 ...
用其它web服务器提供端口也一样,由于python比较方便,这里就用它
使用telnet判断
telnet是windows标准服务,可以直接用;如果是linux机器,需要安装telnet.
用法: telnet ip port
先用telnet连接不存在的端口
[wyq@localhost ~]$ telnet localhost 9000
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
直接提示连接被拒绝
再连接上面提供的端口
[wyq@localhost ~]$ telnet localhost 8080
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
看到"Connected to localhost." 可以知道连接成功了.
后台服务器有什么反映?
[wyq@localhost monitor]$ python -m SimpleHTTPServer 8080
Serving HTTP on 0.0.0.0 port 8080 ...
没有任何反映
此时telnet停住了,随便输入一个字符"a",然后回车
[wyq@localhost ~]$ telnet localhost 8080
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
a
Error response
Error response
Error code 400.
Message: Bad request syntax ('a').
Error code explanation: 400 = Bad request syntax or unsupported method.
Connection closed by foreign host.
再看服务器
[wyq@localhost monitor]$ python -m SimpleHTTPServer 8080
Serving HTTP on 0.0.0.0 port 8080 ...
127.0.0.1 - - [22/Aug/2014 07:15:16] code 400, message Bad request syntax ('a')
127.0.0.1 - - [22/Aug/2014 07:15:16] "a" 400 -
上面是linux环境下telnet连接一个web服务端口的情况.
使用ssh判断
ssh是linux的标准配置并且最常用,可以用来判断端口吗?
用法: ssh -v -p port username@ip
-v 调试模式(会打印日志).
-p 指定端口
username可以随意
连接不存在端口
[wyq@localhost ~]$ ssh -v -p 9000 wyq@localhost
OpenSSH_6.4, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /home/wyq/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 51: Applying options for *
debug1: Connecting to localhost [127.0.0.1] port 9000.
debug1: connect to address 127.0.0.1 port 9000: Connection refused
ssh: connect to host localhost port 9000: Connection refused
"Connection refused"表示端口不可用
连接存在的端口
[wyq@localhost ~]$ ssh -v -p 8080 wyq@localhost
OpenSSH_6.4, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /home/wyq/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 51: Applying options for *
debug1: Connecting to localhost [127.0.0.1] port 8080.
debug1: Connection established.
debug1: identity file /home/wyq/.ssh/id_rsa type 1
debug1: identity file /home/wyq/.ssh/id_rsa-cert type -1
debug1: identity file /home/wyq/.ssh/id_dsa type -1
debug1: identity file /home/wyq/.ssh/id_dsa-cert type -1
debug1: identity file /home/wyq/.ssh/id_ecdsa type -1
debug1: identity file /home/wyq/.ssh/id_ecdsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.4
debug1: ssh_exchange_identification:
debug1: ssh_exchange_identification:
Error response
debug1: ssh_exchange_identification:
debug1: ssh_exchange_identification:
debug1: ssh_exchange_identification:
Error response
debug1: ssh_exchange_identification:
Error code 400.
debug1: ssh_exchange_identification:
Message: Bad request syntax ('SSH-2.0-OpenSSH_6.4').
debug1: ssh_exchange_identification:
Error code explanation: 400 = Bad request syntax or unsupported method.
debug1: ssh_exchange_identification:
ssh_exchange_identification: Connection closed by remote host
"Connection established" 表示已经连上端口
服务器输出
[wyq@localhost ~]$ python -m SimpleHTTPServer 8080
Serving HTTP on 0.0.0.0 port 8080 ...
127.0.0.1 - - [22/Aug/2014 13:32:55] code 400, message Bad request syntax ('SSH-2.0-OpenSSH_6.4')
127.0.0.1 - - [22/Aug/2014 13:32:55] "SSH-2.0-OpenSSH_6.4" 400 -
使用wget判断
wget是linux下的下载工具,需要先安装.
用法: wget ip:port
连接不存在的端口
[wyq@localhost ~]$ wget localhost:9000
--2014-08-22 13:36:42-- http://localhost:9000/
正在解析主机 localhost (localhost)... 127.0.0.1
正在连接 localhost (localhost)|127.0.0.1|:9000... 失败:拒绝连接。
连接存在的端口
[wyq@localhost ~]$ wget localhost:8080
--2014-08-22 13:37:22-- http://localhost:8080/
正在解析主机 localhost (localhost)... 127.0.0.1
正在连接 localhost (localhost)|127.0.0.1|:8080... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2770 (2.7K) [text/html]
正在保存至: “index.html”
100%[======================================>] 2,770 --.-K/s 用时 0s
2014-08-22 13:37:22 (105 MB/s) - 已保存 “index.html” [2770/2770])
总结
提供端口服务,则使用了tcp协议,上面是以web服务器为例。如果服务器是更简单的tcp服务器,三个工具同样适用.
三个工具的共同点是:1.以tcp协议为基础;2.能访问指定端口. 遵循这两点可以找到很多工具.
一般在windows下使用telnet比较方便,linux下个人就比较喜欢用wget.
怎么判断linux22端口是否通,判断端口通不通的几种方法相关推荐
- js判断多边形的坐标点是顺时针还是逆时针的两种方法
js判断多边形的坐标点是顺时针还是逆时针的两种方法 关键算法 通过极值点与其相邻点的构成的矢量走向算出多边形走向 通过计算各左边点所在矢量夹角的角度总和来推算多边形走向 由于arcgis对顺时针生成的 ...
- 3.js中判断数组中是否存在某个对象/值,判断数组里的对象是否存在某个值 的五种方法 及应用场景|判断数组里有没有某对象,有不添加,没有则添加到数组
3.js中判断数组中是否存在某个对象/值,判断数组里的对象是否存在某个值 的五种方法 及应用场景 一.当数组中的数据是简单类型时: 应用js中的indexof方法:存在则返回当前项索引,不存在则返回 ...
- java判断一个字符串是否为空或空字符串(四种方法)
首先需要理解null和" "的区别: null表示这个字符串在栈中没有任何指向因此在堆中没有分配内存空间,如果要调用这个字符串会出现空指针异常 String str = null; ...
- Linux 怎么看端口通不通,判断端口通不通的几种方法
1.使用telnet判断 telnet是windows标准服务,可以直接用:如果是linux机器,需要安装telnet. 用法:telnet ip port 1)先用telnet连接不存在的端口[ro ...
- 测试端口通不通的四种方法
(1)telnet ip port telnet是windows标准服务,可以直接用:如果是linux机器,需要安装telnet. (2)ssh -v -p port username@ip ssh是 ...
- python调用cmd命令释放端口_详解python调用cmd命令三种方法
目前我使用到的python中执行cmd的方式有三种 使用os.system("cmd") 该方法在调用完shell脚本后,返回一个16位的二进制数,低位为杀死所调用脚本的信号号码, ...
- Java学习笔记:模拟实现微信零钱通(面向过程和OOP两种方法)
写在前面:本次一个小测验技术范围非常浅,非常适用于像我这样小白的人练习,并深刻体会面向过程和面向对象最直观的区别. 1.面向过程代码实现: package com.codetest.smallchan ...
- 判断图有无环_判断无向图/有向图中是否存在环
本文主要针对如何判断有向图/无向图中是否存在环的问题进行简单的论述. 一 无向图 1.利用DFS进行判断 利用DFS判断有向图是否存在环,是最为常用的一种方法,虽然这种方法很常用,但可参考的代码的实现 ...
- java判断telnet通不通_(转)测试端口通不通(四种方法)
一般情况下使用"telnet ip port"判断端口通不通.接下来通过本文给大家分享四种方法测试端口通不通,感兴趣的朋友一起学习吧 一般情况下使用"telnet ip ...
最新文章
- android post json格式,Android中post请求传递json数据给服务端的实例
- malloc/free和new/delete的区别
- 【Spring注解系列11】Spring后置处理器BeanPostProcessor用法与原理
- solr 自定义 dismax查询方式
- 互联网加大赛历届作品_匠心筑梦 ——家具漆服务系统2020年度涂装大赛成功举办...
- Mybatis的缓存机制Cache
- Java泛型初探————泛型通配
- 网页版深度学习模型编辑器,搭建运行样样都行,还能3D可视化
- springboot+openFeign+nacos+seata开发实战
- php免费下载手册,php手册|php中文手册下载|好特下载
- 三维图像处理_【图像处理】用于三维物体检测的三维骨干网络
- 博客大全被百度标注为风险网站
- 新手如何写博客(写给大一)
- python成语接龙代码_最全的成语接龙代码(附带有网页版)
- cmyk rgb 数值转换_计算机视觉学习笔记2 图像类型转换
- PyCharm输入法无法切换中英文
- 基于MapReduce的手机上网流量统计分析
- 你好,你是谁,可不可以向我出示源代码让我确认身份
- 为什么Vertu没有成为诺基亚的iPhone?
- Qt写入读取txt文本文件