判断端口是否通
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
免费下载资源
·
转载:https://my.oschina.net/yongqing/blog/305715
使用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." 可以知道连接成功了.
使用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: <head>
debug1: ssh_exchange_identification: <title>Error response</title>
debug1: ssh_exchange_identification: </head>
debug1: ssh_exchange_identification: <body>
debug1: ssh_exchange_identification: <h1>Error response</h1>
debug1: ssh_exchange_identification: <p>Error code 400.
debug1: ssh_exchange_identification: <p>Message: Bad request syntax ('SSH-2.0-OpenSSH_6.4').
debug1: ssh_exchange_identification: <p>Error code explanation: 400 = Bad request syntax or unsupported method.
debug1: ssh_exchange_identification: </body>
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是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.
GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
已为社区贡献14条内容
所有评论(0)