Plan a bounded port scan
Build a deduplicated endpoint plan inside an explicit IPv4 allowlist.
Start with a plan you can inspect
A TCP scanner combines several concerns: choosing destinations, attempting a connection, handling deadlines and interpreting results. Begin with the destination plan. An explicit address and port list is easier to review than an automatically expanded network, and an endpoint limit prevents a small input mistake from creating a large job.
This browser has networking disabled. You will build the same planning and reporting boundaries with fictional addresses and recorded probe outcomes. The optional local scanner makes actual TCP connections when run outside the browser with --execute. Its default only previews; its allowlist records intended scope, not permission to scan someone else's systems.
Validate before publishing
The supplied awk helper validates canonical IPv4 addresses, numeric ports and network-aligned CIDRs. A scope call exposes inclusive numeric bounds only when it succeeds. Compare numbers rather than address prefixes as text. Sort by numeric address and port, and count distinct pairs rather than repeated input rows.
Build the whole plan in a temporary directory. If one row is invalid or outside the allowlist, fail without replacing a previous plan. This course recommends the three intermediate Bash paths, but lessons remain freely accessible. All required scripts use Bash 3.2-compatible syntax and portable Unix command options; the browser itself runs Bash 5.2.
awk -F '\t' 'NR>1 {printf "planned endpoint: %s:%s\n",$1,$2}' candidates.tsv
Put it into practice.
candidates.tsv has header address<TAB>port; scope.txt has one CIDR per line. Use lib/network.awk: ipv4(text) returns -1 or a number; port(text) validates 1–65535 without leading zeros; scope(text) validates a network-aligned CIDR and sets lower/upper. Accept only two-field rows with canonical IPv4, valid port and membership in at least one scope. Deduplicate pairs and allow at most four distinct endpoints (zero is valid). Replace plan.tsv with address<TAB>port and data sorted by numeric address, then numeric port. Any invalid scope or candidate, out-of-scope row, or exceeded cap must exit 2 with “Invalid scan plan” on stderr and leave the old plan unchanged. Do not connect to anything or alter the inputs.
See an explained solution
export LC_ALL=C
work=$(mktemp -d .plan.XXXXXX) || exit 2
trap 'rm -rf "$work"' EXIT
if ! awk -F '\t' -f lib/network.awk -f - scope.txt candidates.tsv > "$work/rows" <<'AWK'
FILENAME==ARGV[1] {if(!scope($0)){bad=1;next}lo[++count]=lower;hi[count]=upper;next}
FNR>1 {
v=ipv4($1);allowed=0
for(i=1;i<=count;i++)if(v>=lo[i] && v<=hi[i])allowed=1
if(NF!=2 || v<0 || !port($2) || !allowed){bad=1;next}
key=$1 SUBSEP $2
if(!(key in seen)){seen[key]=1;total++;printf "%.0f\t%s\t%s\n",v,$1,$2}
}
END {if(bad || total>4)exit 2}
AWK
then printf 'Invalid scan plan\n' >&2;exit 2;fi
printf 'address\tport\n' > "$work/plan"
sort -t $'\t' -k1,1n -k3,3n "$work/rows" | cut -f2,3 >> "$work/plan"
mv "$work/plan" plan.tsv
Planning is separate from execution. Validation precedes replacement, duplicate pairs count once, and numeric sorting gives a stable reviewable scope. Temporary output prevents an invalid candidate from publishing a partial plan.