03 / BUILD A TCP PORT SCANNER · LESSON 10

Distinguish TCP outcomes

Preserve open, refused, timed-out, and missing-observation results without guessing service health.

12 min · learn at your pace

Four outcomes, four meanings

Open means a TCP connection was accepted in the observation. It does not identify the application, prove a successful login, or establish service health. Refused means an explicit refusal was observed. TimedOut means the deadline expired without a conclusive connection result. Error covers other failures or an invalid observation.

Test-LabTcpPort reads supplied observations; it never sends packets. It uses the same output shape a real adapter will provide: ComputerName, Port, Status, ElapsedMs, and Detail. Recorded durations are simulated numbers. The lab does not sleep for them.

A timeout is a budget

app01 has a recorded refusal on port 22 after 4 ms, an open port 443 after 12 ms, and an open port 5985 after 10 ms. With an 8 ms budget, the latter two become TimedOut, with a simulated elapsed value of 8. A larger budget reveals the recorded Open outcomes.

Port 9999 has no supplied observation. The adapter returns Error with a diagnostic instead of assuming the port is closed. That missing-data distinction matters when fixtures or real collectors have incomplete coverage.

Preserve uncertainty

Do not collapse every non-open result into “closed”. A firewall, packet loss, an unavailable host, name resolution, and a refusing endpoint can require different investigation. In a real adapter, connection errors and deadlines supply these categories. In this lesson, the deterministic fixtures let you practise the reporting contract without network access.

Go deeper

Read the official reference.

Try an example.ps1
Import-Module '/home/user/LabFleet.psm1' -Force
Test-LabTcpPort app01 -Port 443 -TimeoutMs 200
Test-LabTcpPort app01 -Port 443 -TimeoutMs 8
YOUR TURN

Put it into practice.

Import the lab module and probe app01 ports 22, 443, 5985, and 9999 with TimeoutMs 8. Emit the four result objects intact, including ComputerName, Port, Status, ElapsedMs, and Detail. Preserve uncertainty and missing-observation errors.

See an explained solution
One way to solve it.ps1
Import-Module '/home/user/LabFleet.psm1' -Force
foreach($number in 22,443,5985,9999) {
    Test-LabTcpPort app01 -Port $number -TimeoutMs 8
}

The time budget changes what can be concluded from the same recorded events. Missing observations remain errors, and a timeout stays inconclusive.