怎么判断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 ...
最新文章
- 格式化输入输出(待更新)
- linux c printf 打印输出null
- python list 深复制_Python列表的深复制和浅复制示例详解
- SAP Cloud for Customer Sales Order Requested Date的业务含义和实现
- app自定义图标 vue_uniapp自定义图标组件
- 深入mysql慢查询设置的详解
- 【复杂系统迁移 .NET Core平台系列】之静态文件
- ACwing 4. 多重背包问题 I(DP)
- Java类类getComponentType()方法与示例
- 换个角度思考勒索攻击事件
- 开发软件快捷键(持续更新中)
- kite:Python 代码自动补全神器
- python制作中秋贺卡图片_中秋贺卡手工制作图片
- Python3 学习第十二弹: 补充something
- 利用 pyspider 框架抓取猫途鹰酒店信息
- plc编程语言有哪几种?
- SpringBoot中调用第三方接口的三种方式
- 2021 年 GitHub 上十大最火 Python 项目,看完之后我裂开了
- php采集今日头条,用php蓝天采集器抓取今日头条ajax的文章内容
- 图片传输到ipfs节点然后将生成的ipfs访问链接存到区块链
热门文章
- Twitter监控系统、Spotify事件交付、Netflix大数据实战——QCon上海2016精彩演讲前瞻...
- 金蝶 列表插件,引入Excel-1,添加按钮,导入界面
- Istio 服务网格学习(一)
- 连接Mysql乱码问题
- 录屏软件的鼻祖是techSmith 的喀秋莎 Camtasia Studio2023功能解锁及安装教程录屏视频编辑软件
- Python保存图片到桌面
- ubuntu18.04系统笔记本电脑合盖后无法唤醒问题解决
- java分页sql语句_「sql分页」sql语句 实现分页 - seo实验室
- Leetcode之重排链表
- python网络自动化_【车联网系统】基于Python实现的现网全自动化测试方案