网络连接测试命令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连接。

相关推荐
Trae_陈冀5 小时前
写测试用例总漏场景还格式乱?我做了个自动生成工具,需求一键转标准用例
agent·测试
初学AI的小高6 小时前
Agent 评测驱动开发:用 pytest 测试工具调用与执行轨迹
agent·测试
得物技术8 小时前
压测AI Agent 治理与评测调优实践
程序员·架构·测试
狂师2 天前
Agent评测工具链大全:Promptfoo、DeepEval 与 LangSmith
人工智能·agent·测试
测开Harvey3 天前
分享一套公司实际业务跑通的接口自动化测试方案:Postman+Newman+Jenkins
测试
野草闲花3 天前
并发用户数、在线用户数与虚拟用户
测试
ClouGence3 天前
Web 自动化测试总是超时?聊聊等待、超时和异步加载
前端·测试
mCell5 天前
AI 时代,我为什么开始追求 100% 的测试覆盖率?
llm·ai编程·测试