Skip to content
mexsic
← Tools

Tool · Rust · v0.1.0

oncep

A TCP port scanner that reports how sure it is of each result.

TCP port scanner with a per-port confidence and an estimated time to completion. It uses ordinary TCP connections, so it needs neither root privileges nor libpcap. Supports IPv4, IPv6 and CIDR ranges.

Terminal with oncep scanning scanme.nmap.org: open ports with their confidence and round-trip time
Language
Rust
Version
v0.1.0
License
MIT
Status
Active

Features

  • 01Per-port confidence: open, closed, filtered or uncertain
  • 02Estimated time while it scans
  • 03No root, no raw sockets, no libpcap
  • 04IPv4, IPv6 and CIDR
  • 05Text, TSV and JSON lines output
  • 06Reproducible scans with --seed

Build

git clone https://github.com/mexsic/oncep.git
cd oncep && cargo build --release

Demo

oncep in action

The target is fixed: scanme.nmap.org, the server the Nmap project provides for testing scanners. It cannot be changed.

Each run executes oncep for real on our server and shows its output as it happens. To avoid overloading the target, if someone ran it less than 30 seconds ago you will see that same run, and runs are limited per visitor and per day.

Target scanme.nmap.org

$

Research

The research behind the tool

A port scanner cannot tell a filtered port from a lost packet with certainty. oncep does not hide that uncertainty: it measures it, publishes it next to every result, and uses it to decide how many attempts are worth spending.

Most port scanners report a state without nuance: open, closed or filtered. Yet the evidence behind each state is not equally strong. A completed connection is near-conclusive proof; a silence can mean a firewall, or just a packet lost on the way.

oncep starts from a concrete question: how sure can we be of each result, and how long until the scan finishes? This page documents the model, the architecture and the design decisions of version 0.1.0.

The problem: silence is ambiguous

A TCP connect scan observes one of four things per attempt: the connection completes (the port is open), the host answers with a refusal (the port is closed), no reply arrives before the timeout, or the network reports the destination as unreachable.

The first two are direct evidence. The third is not: a port filtered by a firewall and a port whose reply was lost produce exactly the same silence. Traditional scanners settle this with a fixed number of retries and publish “filtered” without saying how much evidence supports it.

oncep treats each silence as an observation whose weight depends on the network being measured. If the host has already shown it answers without losing packets, a few silences are enough to conclude that a port is filtered. If we know nothing about the host yet, more are needed.

Architecture

oncep is a single Rust binary of about 2,500 lines, built on the tokio async runtime. A scan flows as follows:

How a scan flowsRust · tokio · ~2,500 lines
  1. 01Targetstargets.rs

    IP, hostname or CIDR · DNS once per name

  2. 02Per-host queuescan.rs

    Sample of 24 ports: did anything answer?

    yes → the remaining ports are released

    no → rest of the host skipped · no-response

  3. 03Pacingscan.rs

    Token bucket (--rate) · ≤ 64 attempts per host

  4. 04TCP connect()probe.rs

    Each attempt with its own timeout

    • connected
    • refused
    • timeout
    • unreachable

    answersilence

rtt.rs

Per-host RTT

RFC 6298 · Karn's algorithm

↺ tunes the wait of the next attempt

eta.rs · progress.rs

Time left

ETA on stderr

confidence.rs

Confidence model

Most likely state and its confidence

Per-port verdict

  • open
  • closed
  • filtered
  • uncertain

output.rs

Output

text · TSV · JSON lines

Each stage names the module that runs it.

Modules

probe.rs
Makes each attempt with connect() and a timeout, and turns operating-system errors into observations. Local resource errors (EMFILE, ENFILE, EAGAIN) put the attempt back on the queue without spending budget, so a descriptor limit is never mistaken for a filtered port.
scan.rs
The scheduler. It keeps a queue per host, paces attempts with a token bucket, spreads work across hosts and applies early stopping.
rtt.rs
Estimates each host's round-trip time to decide how long to wait on each attempt.
confidence.rs
Turns each port's observations into a state and a confidence.
eta.rs and progress.rs
Compute and display the time left.
targets.rs
Parses ports, targets and CIDR ranges, and shuffles the port order with a reproducible seed.
output.rs
Writes results as text, TSV or JSON lines.

Concurrency and pacing

Default concurrency is derived from the system's open-file limit: (limit − 64) / 2, kept between 32 and 512. No host gets more than 64 simultaneous attempts, so a slow target cannot take over the scan. A token bucket caps attempts per second (--rate, 2,000 by default).

Ports are visited in random order to avoid the sequential pattern many detection systems recognize. The order comes from a SplitMix64 generator whose seed is printed in the summary, so any scan can be repeated exactly with --seed.

Confidence model

Each port has a budget of attempts (3 by default). A reply finishes the port; silence spends budget. At the end, oncep computes the confidence of the most likely state:

Confidence per state
open

1 − 0.01n

n = completed connections
a single one: 0.99

closed

1 − 0.03n

n = refusals (RST)
a single one: 0.97

filtered

1 / (1 + (p / 0.98)k)

k = silent attempts
depends on the network

p = 90 % upper bound on the host's loss · Beta(1 + losses, 9 + successes)

The assumed error rates are conservative: we accept that 1 in 100 completed connections might not indicate a real service (a transparent proxy, for instance), and that 3 in 100 refusals might come from a device in between. That is why one connection publishes open at 0.99 and one refusal publishes closed at 0.97.

The host's loss

The value p is the heart of the model. For each host, oncep counts the attempts that failed on ports that later did answer: those are real network losses. It updates a Beta distribution with them and uses its 90th percentile as a pessimistic estimate of loss. With no data, the Beta(1, 9) prior gives p = 0.2257; after 40 answered attempts with no loss, p drops to 0.0459.

The effect on silences is direct:

Confidence of filtered by silences
  • unmeasured host · p = 0.2257
  • measured host, no loss · p = 0.0459
SilencesUnmeasured hostMeasured host
10.8130.955
20.9500.998
30.988> 0.999
Below the threshold the port is reported as uncertain. The axis starts at 0.75.

A state is published only if its confidence reaches --min-confidence (0.95 by default). Below that, the port is reported as uncertain. That state is not an error but an honest conclusion: the available budget did not produce enough evidence.

Contradictory evidence

If the same port produces both connections and refusals, oncep computes the posterior probability of each state from a likelihood table for open, closed and filtered, and publishes the most likely one with its probability. One connection and one refusal, for example, give about 0.66: the port stays uncertain.

Adaptive timeouts

Waiting too long makes a scan slow; waiting too little turns late replies into false silences. oncep estimates each host's round-trip time with TCP's standard algorithm (RFC 6298):

Adaptive timeoutRFC 6298
SRTT←(1 − ⅛) · SRTT + ⅛ · R
RTTVAR←(1 − ¼) · RTTVAR + ¼ · |SRTT − R|
RTO=SRTT + 4 · RTTVAR500 ms until 4 samples exist

wait for attempt n=RTO · 1.5n − 1

between 100 ms and --timeout

A silent port, with the defaults

n = 1

500 ms

n = 2 · ×1.5

750 ms

n = 3 · ×1.5

1,125 ms

Σ 2,375 ms

An attempt that times out is never used as a sample (Karn's algorithm).

Following Karn's algorithm, an attempt that times out is not used as a sample, because we do not know how long it would have taken. With the defaults, a silent port waits 500, 750 and 1,125 ms across its three attempts.

Detecting hosts that do not answer

Scanning 65,535 ports of a host that is down wastes minutes. Before the rest, oncep probes a sample of up to 24 ports: the first and last of the range, the common ports present in the list (22, 80, 443, 3389, among others) and others spread evenly.

If none of them answers, the rest of the host is skipped and reported as no-response, with a confidence computed from the silent attempts. A single reply releases every remaining port. --force turns this optimization off.

Early stopping

The attempt budget is a ceiling, not an obligation. A reply finishes the port at once. A silence can finish before the budget when the host is already measured (at least 8 replies) and the confidence for filtered already reaches the threshold. On clean networks this considerably reduces the number of attempts. --insist always spends the full budget.

Estimating the time left

The time left is computed from the pending ports N, the effective concurrency C and the expected cost of each port:

Time-left estimate

ETA = (N · E[slot] + residual)C

E[slot] = (1 − q) · RTTp95 + q · Tsilent

N
ports left
C
effective concurrency
q
fraction of ports that end in silence (0.5 until 32 have finished)
RTTp95
95th percentile of response times
Tsilent
sum of the waits of a port that spends its whole budget
residual
time left on the attempts in flight

q is the fraction of ports that end in silence, RTT_p95 the 95th percentile of response times, and T_silent the sum of the waits of a port that spends its whole budget. Until 32 ports have finished, q is 0.5 and the estimate is shown with a tilde (~) to mark it as preliminary. The JSON also carries the bounds eta_lo and eta_hi: the scan if everything answered, and if everything stayed silent.

Design decisions

  • Connect scan, no raw sockets: oncep needs neither root nor libpcap and behaves the same on macOS and Linux. In exchange, every open port completes the TCP handshake and is logged by the target. It is a tool for auditing systems you own or are authorized to test, not for going unnoticed.
  • Rust: the tool processes network replies we do not control, and memory safety removes entire classes of vulnerabilities. The result is a binary with no system dependencies.
  • Reproducible results: the seed, version and parameters are part of the output, so another team can repeat the same scan and compare.
  • Machine-readable output: JSON lines and TSV let other tools consume oncep without parsing text.

Limitations

  • TCP connect only: it does not send half-open SYN probes, scan UDP, fingerprint services or spoof its source address.
  • The model assumes attempts are independent and that loss is uniform within a host. A firewall that rate-limits its replies can break that assumption.
  • The error rates assumed for open and closed are fixed; they are not estimated from the data.

How the demo works

The terminal on this page runs the same binary in a Vercel function and streams its output as it happens. The target, ports and timing are fixed, and nothing in the request reaches oncep. A new scan starts at most every 30 seconds and up to 60 times a day; anyone who arrives while one is running watches that same scan, and outside those limits the latest real scan is replayed. Each visitor also has a run limit of their own.

The target is scanme.nmap.org, the server the Nmap project provides for testing scanners. Only scan systems you are authorized to assess.

Next step

One call to understand your case.

You tell us what you want to protect and what you are being asked for. We tell you which service applies, what scope makes sense and whether we are not the right fit. Then you receive a written proposal.