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

相关推荐
钱栈up1 天前
烧结趋势页台车速度曲线凭空消失:一次\\\"去重\\\"误杀的配置修复
后端·测试
xbzb2 天前
服务器与网络:从一台裸机到能联网跑服务(5 篇)
服务器·网络·ip·raid·blog.csdn.net·article
林壮Allen2 天前
自检脚本说「全绿」,凭什么信它:用两条负对照把橡皮图章揪出来
后端·测试
狂师2 天前
推荐一款手机自动化神器:phone-harness
前端·开源·测试
狂师3 天前
别只会用 Playwright、Appium了?这 8 款开源 AI 自动化工具实测推荐!
人工智能·开源·测试
Jame哥5 天前
从 SQLite 的 590 倍测试看“小项目如何做工程质量
sqlite·开源·测试·工程质量
bufengwangluo5 天前
动态代理IP是什么?从IP池到自动切换的工作机制解读
服务器·网络·ip
一条Go6 天前
全链路 e2e:一次跑出 20 个现象,收敛成 5 个根因
后端·github·测试
EmbeddedChen6 天前
Linux 怎么查看 IP 地址和网络状态?常用网络命令入门
linux·网络·ip·route·ping