Skip to content

Test-Connection with -TcpPort only tries IPv6 connection for localhost #17383

@javidcf

Description

@javidcf

Prerequisites

Steps to reproduce

  1. Open an TCP server on some local port of the IPv4 loopback interface. For example, with Python 3 run a simple HTTP server with python -m http.server --bind 127.0.0.1 8000.
  2. In another terminal, run Test-Connection localhost -TcpPort 8000.

Expected behavior

The command returns True.

Actual behavior

The command returns False.

If we run Test-Connection 127.0.0.1 -TcpPort 8000 or Test-Connection localhost -IPv4 -TcpPort 8000, the returned result is True. The command Test-NetConnection localhost -Port 8000 does give the correct answer, although it first tries connecting to ::1 : 8000 and fails.

Error details

It seems Test-Connection is just testing the first loopback address it is finding, which is the IPv6 ::1 address. I think this behaviour is surprising, especially since locally deployed servers are most frequently bound to 127.0.0.1 only.

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.4
PSEdition                      Core
GitCommitId                    7.2.4
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.Resolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions