Report inclusive membership for saved address and canonical network pairs without DNS, socket access or changing firewall rules. Reads saved text only; never sends network requests.
Before you start
- Save as recipe.cjs and run with Node.js 22: node recipe.cjs < input.txt. Supply no CLI arguments.
- Each nonempty LF-separated record must be exactly ADDRESS NETWORK/PREFIX, with one ASCII space. Exactly empty lines are ignored; whitespace is not trimmed. CR, tabs, NUL, comments and non-ASCII characters are rejected.
- IPv4 addresses must contain exactly four decimal octets from 0 through 255, with no leading zeros except the single digit 0. Prefixes must use canonical decimal spelling from 0 through 32. Networks with nonzero host bits are rejected rather than normalized.
- Reads at most 65537 stdin bytes and rejects input exceeding 65536 bytes. Accepts at most 100 nonempty records.
- Uses TextDecoder from node:util with fatal:true and ignoreBOM:true for strict UTF-8 decoding, followed by explicit leading BOM rejection.
- Validates all input before emitting exactly one compact JSON object followed by LF. Output has only a checks array of objects containing address, cidr and boolean contains. Original spellings, order and duplicates are preserved; empty input produces {"checks":[]}. Success exits 0 with empty stderr.
- Membership includes network and inclusive last addresses, including both /31 addresses and the sole /32 address. Arithmetic uses exact integers, powers of two and Math.floor without bitwise operations or host enumeration.
- Invalid input, extra arguments, decoding errors and stdin read failures produce empty stdout, exactly error: invalid input followed by LF on stderr, and exit status 2.
Build and check
- Save the example as recipe.cjs.
- Create input.txt with records in the documented exact format.
- Run the documented command; inspect the JSON result.
- Exit 2 means rejected input; no partial successful output is emitted.
Limits to understand
- Only node:fs and node:util are loaded, for bounded stdin reads and strict decoding. There is no file-path access, environment inspection, network access, DNS, subprocess execution, dependency use or firewall modification.
- IPv4 membership only; no IPv6, hostnames, URL forms, wildcard masks, alternate netmask forms or silent normalization.
- Membership makes no statement about routability, trust, reachability, security or device availability. Ranges include all bit patterns, not merely usable hosts; /0 covers 4294967296 addresses and /32 covers one.
- Output-write and allocation failures are outside the input-error guarantee.
- IPv4 text only; no DNS, sockets, IPv6, firewall configuration or security/routability assessment.
- LF-only ASCII input, at most 65536 bytes and 100 nonempty records. Blank lines ignored; duplicates retained.
- Network input must have zero host bits. Both network and inclusive last addresses count as members.
Run it
node recipe.cjs < input.txtExample input
192.0.2.129 192.0.2.0/24
Expected output
{"checks":[{"address":"192.0.2.129","cidr":"192.0.2.0/24","contains":true}]}
