Connection refused — a firewall or proxy may be blocking it (ECONNREFUSED) PS C:...

2026年10月10日 19:44 12.20 秒 success

错误信息

API Error: Connection refused — a firewall or proxy may be blocking it (ECONNREFUSED) PS C:\WINDOWS\system32> Test-NetConnection -ComputerName 127.0.0.1 -Port 64755 警告: TCP connect to (127.0.0.1 : 64755) failed ComputerName : 127.0.0.1 RemoteAddress : 127.0.0.1 RemotePort : 64755 InterfaceAlias : Loopback Pseudo-Interface 1 SourceAddress : 127.0.0.1 PingSucceeded : True PingReplyDetails (RTT) : 0 ms TcpTestSucceeded : False PS C:\WINDOWS\system32> Test-NetConnection -ComputerName 127.0.0.1 -Port 64755 -SourcePort 64756 Test-NetConnection : 找不到与参数名称“SourcePort”匹配的参数。 所在位置 行:1 字符: 56 + ... t-NetConnection -ComputerName 127.0.0.1 -Port 64755 -SourcePort 64756 + ~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Test-NetConnection],ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Test-NetConnection PS C:\WINDOWS\system32>

AI 解决方案

🌐 错误翻译


原文:API Error: Connection refused — a firewall or proxy may be blocking it (ECONNREFUSED)
译文:API错误:连接被拒绝 — 可能是防火墙或代理阻止了连接 (ECONNREFUSED)
原文:Test-NetConnection : 找不到与参数名称“SourcePort”匹配的参数。
译文:Test-NetConnection:未找到与参数名称“SourcePort”匹配的参数。

🎯 原因分析


  • 连接拒绝(ECONNREFUSED):目标端口 64755 上没有服务监听,导致 TCP 连接尝试失败(TcpTestSucceeded: False)。常见原因:服务未启动、服务绑定地址错误、端口被防火墙拦截。

  • 参数错误:Test-NetConnection 命令不支持 -SourcePort 参数,导致参数绑定异常。
  • 💡 解决方案


    # 1. 检查端口监听状态(确认服务是否运行)
    Get-NetTCPConnection -LocalPort 64755 -ErrorAction SilentlyContinue
    
    # 2. 启动/重启服务(假设服务名为 MyService,根据实际替换)
    Start-Service -Name "MyService"
    
    # 3. 检查防火墙规则(允许 64755 端口)
    netsh advfirewall firewall add rule name="AllowPort64755" dir=in action=allow protocol=TCP localport=64755
    

    🛡️ 预防措施


  • 启动前检查:在应用启动逻辑中添加端口可用性检测(如使用 netstat 或尝试绑定端口),避免无服务监听。

  • 参数校验:执行命令前通过 Get-Help <命令> 确认参数列表,避免使用不存在的参数。