暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

探测端口的连通性windows和linux环境下

原创 黑獭 2024-07-02
149

介绍

    在我们的日常安装和运维过程总免不了和网络打交道,探测网络和端口的连通性是个比较常见的工作,过程中往往由于主机缺乏某些工作造成我们的探测受阻,现在我们就介绍几款linux和windows下的端口探测命令供大家学习。

LINUX下的探测命令:

(1)nc探测 

nc探测 端口放开的情况:[root@test ~]# nc -vz 192.168.75.2 1521Ncat: Version 7.50 ( https://nmap.org/ncat )Ncat: Connected to 192.168.75.2:1521.Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.端口不通的情况:[root@test ~]# nc -vz 192.168.75.2 1522Ncat: Version 7.50 ( https://nmap.org/ncat )Ncat: Connection refused.
(2).telnet 探测
端口不通的情况:[root@test ~]# telnet 192.168.75.2 1522Trying 192.168.75.2...telnet: connect to address 192.168.75.2: Connection refused端口放开的情况:[root@test ~]# telnet 192.168.75.2 1521Trying 192.168.75.2...Connected to 192.168.75.2.Escape character is '^]'.
(3).nmap 探测
端口放开的情况:[root@test ~]# nmap  -p 1521 192.168.75.2Starting Nmap 6.40 ( http://nmap.org ) at 2024-07-01 23:02 EDTmass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-serversNmap scan report for 192.168.75.2Host is up (0.000093s latency).PORT     STATE SERVICE1521/tcp open  oracleNmap done: 1 IP address (1 host up) scanned in 0.05 seconds端口不通的情况:[root@test ~]# nmap  -p 1522 192.168.75.2Starting Nmap 6.40 ( http://nmap.org ) at 2024-07-01 23:02 EDTmass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-serversNmap scan report for 192.168.75.2Host is up (0.000077s latency).PORT     STATE  SERVICE1522/tcp closed rna-lmNmap done: 1 IP address (1 host up) scanned in 0.04 seconds

(4).echo探测

在Unix/Linux环境下,你可以使用echo命令结合特殊的设备文件/dev/tcp/hostname/port 来间接测试一个远程主机上的指定端口是否开放。端口放开的情况:[root@test ~]# echo >/dev/tcp/192.168.75.2/1521端口不通的情况:[root@test ~]# echo >/dev/tcp/192.168.75.2/1522-bash: connect: Connection refused-bash: /dev/tcp/192.168.75.2/1522: Connection refused当命令执行后,若端口是开放的,命令不会有任何输出并且会立即返回命令提示符;若端口未开放或连接失败,则可能由于网络问题、防火墙限制等原因导致命令执行失败,通常会显示错误信息,比如“Permission denied”、“Connection refused”或“Network is unreachable”。不过需要注意的是,这种方法只适用于那些支持此特性的Bash环境,不具有普遍性,而且它并不会像专门的网络工具(如telnet、nc或netcat)那样提供详细的连接状态信息。


WINDOWS下的探测命令:

在Windows系统下,你需要使用其他工具或命令来测试端口

(1)Test-NetConnection 探测

成功的情况:PS C:\Users\Dell> Test-NetConnection -ComputerName 192.168.75.2 -Port 1521ComputerName     : 192.168.75.2RemoteAddress    : 192.168.75.2RemotePort       : 1521InterfaceAlias   : VMware Network Adapter VMnet1SourceAddress    : 192.168.75.1TcpTestSucceeded : True失败的情况:PS C:\Users\Dell> Test-NetConnection -ComputerName 192.168.75.2 -Port 1522                                                     警告: TCP connect to (192.168.75.2 : 1522) failed                                                                                                                                                                                                             ComputerName           : 192.168.75.2RemoteAddress          : 192.168.75.2RemotePort             : 1522InterfaceAlias         : VMware Network Adapter VMnet1SourceAddress          : 192.168.75.1PingSucceeded          : TruePingReplyDetails (RTT) : 0 msTcpTestSucceeded       : False这个工具依赖powershell 
(2).telnet探测
telnet探测:成功的情况:PS C:\Users\Dell> telnet 192.168.75.2 1521成功后等待相应失败的情况:PS C:\Users\Dell> telnet 192.168.75.2 1522正在连接192.168.75.2...无法打开到主机的连接。 在端口 1522: 连接失败
(3).nmap
windows下也可以安装nmap进行探测
————————————————————————————微信公众号:天高弋猎墨天轮:https://https://www.modb.pro/u/3738ITPUB:https://blog.itpub.net/69924215/————————————————————————————


「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论