当前位置: 代码网 > 服务器>服务器>Linux > Linux测试端口连通性的5种方法

Linux测试端口连通性的5种方法

2024年07月03日 Linux 我要评论
1、curl(1)curl -v ip:port[root@localhost ~]# curl -v 192.168.120.15:37777* about to connect() to 192.

1、curl

(1)curl   -v  ip:port

[root@localhost ~]# curl -v 192.168.120.15:37777
* about to connect() to 192.168.120.15 port 37777 (#0)
*   trying 192.168.120.15...
* connected to 192.168.120.15 (192.168.120.15) port 37777 (#0)
> get / http/1.1
> user-agent: curl/7.29.0
> host: 192.168.120.15:37777
> accept: */*
>

(2)curl  -kv https://ip:port

​
[root@localhost ~]# curl -kv https://192.168.12.15:3789
 
* about to connect() to 192.168.12.15 port 3789 (#0)
*   trying 192.168.12.15...
* connected to 192.168.12.15 (192.168.12.15) port 3789 (#0)
* initializing nss with certpath: sql:/etc/pki/nssdb
* skipping ssl peer certificate verification
* ssl connection using tls_ecdhe_rsa_with_aes_128_gcm_sha256
* server certificate:
*       subject: cn=cn.com.ca.d6.agent
*       start date: 4月 26 03:51:05 2021 gmt
*       expire date: 4月 26 03:51:05 2041 gmt
*       common name: cn.com.ca.d6.agent
*       issuer: cn=cn.com.ca.d6.agent
> get / http/1.1
> user-agent: curl/7.29.0
> host: 192.168.12.15:3789
> accept: */*
>
< http/1.1 404
< connection:close
< content-length:22
< content-type:text/html
< x-frame-options:sameorigin
<
* closing connection 0
<html>not found</html>

2、nc

(1)nc -nv    ip  port

[root@localhost ~]# nc -nv 192.168.12.15 3789
ncat: version 7.50 ( https://nmap.org/ncat )
ncat: connected to 192.168.12.15:3789.
^c

(2)nc -nvv  ip  port

​
[root@localhost ~]# nc -nvv 192.168.12.15 3789
ncat: version 7.50 ( https://nmap.org/ncat )
ncat debug: using system default trusted ca certificates and those in /usr/share/ncat/ca-bundle.crt.
ncat debug: unable to load trusted ca certificates from /usr/share/ncat/ca-bundle.crt: error:02001002:system library:fopen:no such file or directory
libnsock nsi_new2(): nsi_new (iod #1)
libnsock nsock_connect_tcp(): tcp connection requested to 192.168.12.15:3789 (iod #1) eid 8
libnsock nsock_trace_handler_callback(): callback: connect success for eid 8 [192.168.12.15:3789]
ncat: connected to 192.168.12.15:3789.
libnsock nsi_new2(): nsi_new (iod #2)
libnsock nsock_read(): read request from iod #1 [192.168.12.15:3789] (timeout: -1ms) eid 18
libnsock nsock_readbytes(): read request for 0 bytes from iod #2 [peer unspecified] eid 26
^c

3、ssh

(1)ssh  -v  -p  port  username@ip      // username任意

[root@localhost ~]# ssh -v -p 3789 root@192.168.12.15
openssh_7.4p1, openssl 1.0.2k-fips  26 jan 2017
debug1: reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: applying options for *
debug1: connecting to 192.168.120.15 [192.168.12.15] port 3789.
debug1: connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: key_load_public: no such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: no such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: no such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: no such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: no such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: no such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: no such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: enabling compatibility mode for protocol 2.0
debug1: local version string ssh-2.0-openssh_7.4
^c

4、wget

(1)wget   ip:port

[root@localhost ~]# wget 192.168.12.15:3789
--2023-03-25 17:05:20--  http://192.168.12.15:3789/
正在连接 192.168.120.15:37777... 已连接。
已发出 http 请求,正在等待回应... ^c​

5、telnet

(1)telnet   ip   port

[root@localhost ~]# telnet 192.168.12.15 3789
trying 192.168.12.15...
connected to 192.168.12.15.
escape character is '^]'.
^cconnection closed by foreign host.

端口通 != 业务通

tcp端口通,上面跑的http业务可能不通(代理限制)。

tcp层:nc,ssh,telnet

http层:curl,wget

到此这篇关于linux测试端口连通性的5种方法的文章就介绍到这了,更多相关linux测试端口内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com