网络连接测试命令Test-NetConnection


版权声明


Test-NetConnection概述

使用Test-NetConnection测试TCP端口时,基本语法如下:

powershell 复制代码
Test-NetConnection 主机地址 -Port 端口号

其中,主机地址用于指定目标服务器,可以填写IP地址或主机名;-Port用于指定需要测试的TCP端口。

命令执行后,PowerShell会尝试与目标服务器的指定端口建立TCP连接,并返回测试结果。常见结果包含以下内容:

text 复制代码
ComputerName     : 目标主机
RemoteAddress    : 目标IP地址
RemotePort       : 目标端口
InterfaceAlias   : 本地网络接口
SourceAddress    : 本地IP地址
TcpTestSucceeded : True

ComputerName表示测试的目标主机,RemoteAddress表示实际连接的目标IP地址,RemotePort表示测试的目标端口,InterfaceAlias表示Windows使用的网络接口,SourceAddress表示本次连接使用的本地IP地址。

进行TCP端口测试时,主要关注TcpTestSucceeded。

text 复制代码
TcpTestSucceeded : True

表示Windows能够与目标服务器的指定TCP端口建立连接。

text 复制代码
TcpTestSucceeded : False

表示TCP连接没有成功建立。

Test-NetConnection测试常见端口

下面分别使用Test-NetConnection测试MySQL、Redis和RabbitMQ在Linux服务器中使用的几个端口。

本教程中使用xxx.xxx.158.246的写法隐藏了真实IP,请在测试时使用具体IP。

MySQL 3306端口

MySQL传统客户端通常使用3306端口。执行以下命令测试3306端口:

powershell 复制代码
PS C:\Users\yy> Test-NetConnection xxx.xxx.158.246 -Port 3306

执行结果如下:

text 复制代码
ComputerName     : xxx.xxx.158.246
RemoteAddress    : xxx.xxx.158.246
RemotePort       : 3306
InterfaceAlias   : 以太网
SourceAddress    : 10.0.xxx.xxx
TcpTestSucceeded : True

Redis 6379端口

Redis默认使用6379端口。执行以下命令测试6379端口:

powershell 复制代码
PS C:\Users\yy> Test-NetConnection xxx.xxx.158.246 -Port 6379

执行结果如下:

text 复制代码
ComputerName     : xxx.xxx.158.246
RemoteAddress    : xxx.xxx.158.246
RemotePort       : 6379
InterfaceAlias   : 以太网
SourceAddress    : 10.0.xxx.xxx
TcpTestSucceeded : True

RabbitMQ 5672端口

RabbitMQ通常使用5672端口提供应用程序连接。执行以下命令测试5672端口:

powershell 复制代码
PS C:\Users\yy> Test-NetConnection xxx.xxx.158.246 -Port 5672

执行结果如下:

text 复制代码
ComputerName     : xxx.xxx.158.246
RemoteAddress    : xxx.xxx.158.246
RemotePort       : 5672
InterfaceAlias   : 以太网
SourceAddress    : 10.0.xxx.xxx
TcpTestSucceeded : True

RabbitMQ Management 15672端口

RabbitMQ启用Management插件后,通常使用15672端口提供Web管理界面。执行以下命令测试15672端口:

powershell 复制代码
PS C:\Users\yy> Test-NetConnection xxx.xxx.158.246 -Port 15672

执行结果如下:

text 复制代码
ComputerName     : xxx.xxx.158.246
RemoteAddress    : xxx.xxx.158.246
RemotePort       : 15672
InterfaceAlias   : 以太网
SourceAddress    : 10.0.xxx.xxx
TcpTestSucceeded : True

以上四次测试中的TcpTestSucceeded均为True,说明当前Windows电脑能够分别建立到Linux服务器3306、6379、5672和15672端口的TCP连接。

相关推荐
seowmt37 分钟前
GEO效果该什么时候看数据:从立项到复盘的时间线复盘
算法·ip·seo·geo·faq
g3voip19 小时前
工业防水电话到底怎么选?隧道、管廊与码头的需求差异
服务器·网络·信息与通信·ip
KKWOO1 天前
100 万次回归测试,究竟覆盖了多少种真实业务逻辑?
测试
ClouGence1 天前
敏捷开发如何做好测试?一篇讲清流程与实践
测试·敏捷开发
linoWu1 天前
1.接口自动化框架最小demo
测试
kevinccbsg1 天前
AI Agent 说测试都通过了?看着它跑一遍
测试
安替-AnTi1 天前
不用 root:我用 Tailscale 打通了云手机的 ADB 通道
adb·测试·调试·云手机·claude code
sbjdhjd1 天前
从 VLAN 到 MSTP 的交换网络入门
网络·计算机网络·mac·ip·stp·vlan·交换机
狂师1 天前
夯爆了!又一款开源企业级一站式AI智能测试平台!(附平台架构、技术选型)
人工智能·测试·全栈
雪域迷影1 天前
MacOS中杀掉某个端口占用的进程
macos·端口·强杀进程