Skip to content

TCP port range (tcp_port_range) ​

Tries a list or range of TCP ports in one poll, a few at a time, and counts the ports that are open, closed and filtered. It can check the result against the ports that must be open and the ports that must not be, and names the ports that are not as they should be.

Use it where a set of ports is the thing to watch: the services a server must offer (22, 80, 443), the services it must not offer (23, 445, 3389 on a machine facing the internet), or a firewall's rule set, checked from the other side with "these are open and nothing else from 1 to 1024 is".

For one port, with a check of the server's greeting, use the tcp_port sensor.

What it looks like ​

The page of a tcp_port_range sensor in the light theme

The sensor's page after a few polls. In the dark theme: the sensor's page. The form for adding it: light, dark.

Channels ​

KeyNameUnitDefault limits
open_countOpen portsnonenone
closed_countClosed portsnonenone
filtered_countFiltered portsnonenone
connect_avg_msConnect time (average of open ports)mswarning above 1000, error above 3000. Only when a port was open
unexpected_countPorts not as expectednonenone. Only when expected_open, expected_closed or others_closed is set

Open, closed and filtered are the three answers a port gives. Open: the connection was made. Closed: the host answered that nothing listens there (a reset). Filtered: nothing came back in time, or the network refused the packet in some other way: a firewall is in the way. The three add up to the number of ports tried.

The sensor is Down when a port in expected_open is not open, or a port that must not be open is. A port must not be open if it is in expected_closed, or, with others_closed set, if it is not in expected_open. Closed and filtered both satisfy "must not be open". The message names the ports, for instance expected open but not: 443 filtered, 3389 closed; open but should not be: 23. Without any expectation the sensor only counts and is never Down because of a port.

Parameters ​

ParameterDefaultMeaning
portsnone, requiredThe ports to try: a list of ports and ranges such as 22,80,443 or 1-1024 or 20-25,8000-8100. At most 1024 ports.
expected_opennonePorts that must be open, in the same notation. Each must be one of ports.
expected_closednonePorts that must not be open. Each must be one of ports and none may also be in expected_open.
others_closedfalseTreat every port of ports that is not in expected_open as one that must not be open.
concurrency25Connections attempted at once, 1 to 100.
connect_timeout_ms1000How long to wait for each connection, 50 to 10000.

Suggested interval: 300 seconds. No credential.

The poll must be able to finish. Ports are tried concurrency at a time, and a filtered port takes the whole connect_timeout_ms. In the worst case a poll takes the number of ports, divided by the concurrency and rounded up, times the timeout. The sensor shortens the timeout of each port so that the worst case fits inside the poll timeout, and when that would leave less than 50 ms a port the poll fails with a configuration message that says to raise the timeout or the concurrency or to try fewer ports. A thousand ports at 25 at a time on a host that filters all of them need a poll timeout of about forty seconds at the default connect timeout.

On the target and the probe host ​

  • Nothing is installed on the target. Every connection is a plain TCP handshake that is closed at once; no data is sent. Some intrusion detection systems take a run of connections to many ports of a host for a port scan, which it is. Tell whoever runs yours before you point this at a range on a machine that is not yours.
  • The result is how the target looks from the probe. A firewall that treats the probe differently from other clients gives a different answer for them.

Failures ​

The sensor reports ports, not errors, and a host that cannot be reached at all is a host whose ports are all filtered.

MessageMeaning
N ports at C at a time need more than the T ms poll timeout allows ... (kind config)The ports cannot all be tried within the poll timeout. Raise the timeout, raise concurrency, or try fewer ports.
expected open but not: ... / open but should not be: ...A successful poll that is Down; the ports are named.

Verification ​

Run on the loopback interface against listeners the test opens and ports it has just closed (open and closed), with scripted answers for filtered ports, the expectations, the notation, and the limit on connections in flight (a client that counts them: all the allowed slots are used and none is exceeded). Against a lab target: a host with one open port and four closed ports around it, the same behind a 50 ms delay (the handshake time follows), and an address that drops everything (all five filtered, and the missing open port named). Not seen: a firewall that rejects with an ICMP error instead of dropping (the sensor counts any failure other than a refusal as filtered), IPv6, and ranges of many hundreds of ports against a real host.

The live tests read their targets from the environment and say so and return when they are not set:

VariableMeaning
PROBEWARD_TEST_NETEM_CLEAN, PROBEWARD_TEST_NETEM_DELAY50, PROBEWARD_TEST_NETEM_BLACKHOLEAddresses of a target with no impairment, with a 50 ms delay on what it sends back, and one that sends back nothing.
PROBEWARD_TEST_NETEM_OPEN_PORTA port that is open on the first two, with the two ports on either side of it closed.
sh
cargo test -p probeward-sensors --test live_quality port_range -- --nocapture

AGPL-3.0-only