IP Input
One box for an IP address or a CIDR block that normalises what it is given to the single spelling the RFCs allow, says what a prefix is worth in addresses, and refuses the two IPv4 forms whose readings disagree instead of picking one. Reach for it wherever a person types an address rather than a program emitting one: a firewall rule or allowlist entry, an SSH or VPN access list, subnet planning, a DNS A or AAAA record, the upstream for a proxy or load balancer, a monitoring or scan target, a BGP or route-table entry, a rate-limit or geo-block exception, a Kubernetes or security-group CIDR, and the search box where somebody pastes the source address out of a log. Common asks it answers: "ip input react", "ip address input component", "shadcn ip input", "cidr input react", "subnet input component", "ipv4 input validation react", "ipv6 input react", "validate ip address javascript", "ip address regex javascript", "cidr validation javascript", "parse cidr javascript", "subnet mask calculator javascript", "how many hosts in a /24", "how many addresses in a /16", "prefix length to number of hosts", "/31 usable addresses", "ipv6 /64 how many addresses", "normalize ipv6 address javascript", "rfc 5952 canonical ipv6", "ipv6 compare two addresses javascript", "are these two ipv6 addresses the same", "ipv6 leading zeros equal", "ipv4 mapped ipv6 ::ffff", "::ffff:192.0.2.1 validation", "ip with leading zero octal", "010.0.0.1 is 8.0.0.1", "ssrf leading zero bypass", "127.1 is 127.0.0.1", "why does 127.1 work in browser", "net.isIPv4 rejects 127.1", "inet_aton short form javascript", "2130706433 ip address", "0x7f000001 ip", "cidr host bits set error", "192.168.1.5/24 is not a network", "ipv6 zone id fe80::1%eth0", "netmask from prefix length javascript", "0.0.0.0/0 means all addresses", "ip subnet form validation", "allowlist ip entry form", "firewall rule input component", "IP 入力 react", "IPアドレス 入力 コンポーネント", "CIDR 入力 バリデーション", "サブネット 台数 計算", "IPv6 正規化 javascript", "先頭ゼロ IP 8進数", "ホストビット CIDR エラー". **A text box with `/^(\\d{1,3}\\.){3}\\d{1,3}$/` in front of it is wrong about four separate things, and every one of them has been a CVE class or an outage.** They are: which strings are addresses, whether two strings are the same address, how big a prefix is, and what an empty box means. **The two IPv4 spellings whose readings disagree are refused rather than resolved, and the field says who disagrees.** Measured, the WHATWG URL parser — which is to say every browser, and curl — reads `127.1`, `127.0.1`, `2130706433`, `0x7f.1`, `0x7f000001` and `0177.0.0.1` all as `127.0.0.1`, and `192.168.257` as `192.168.1.1`, while `net.isIPv4` in the very same Node process calls every one of them invalid. "Is this a valid address" has two answers inside one runtime, so a field that quietly takes either one is choosing which tool downstream gets surprised; each is reported with its expansion named, on a control that puts it in the box when the reader says so. **A leading zero is the dangerous one, because the two readings are different hosts rather than two spellings of one.** Measured: `new URL("http://010.0.0.1").hostname` is `8.0.0.1`, not `10.0.0.1` — a leading zero makes the octet octal — and `0177.0.0.1` is `127.0.0.1` where a zero-stripper reads `177.0.0.1`. An allowlist that stores the text and a parser that resolves it octal then disagree about who is allowed in, which is exactly the shape of the leading-zero SSRF bypass. The field names both readings and refuses, because offering one would be picking. The 8 and the 9 are a separate case worth knowing: `09.0.0.1` and `08.0.0.1` are not URLs at all (measured), since 8 and 9 are not octal digits. **Identity is decided on the bytes, because the strings lie.** Each of these pairs is two valid spellings of one address, and `===` says they differ: `2001:db8::1` against `2001:0db8:0000:0000:0000:0000:0000:0001`, `::1` against `0:0:0:0:0:0:0:1`, `2001:DB8::1` against `2001:db8::1`, and `::ffff:192.0.2.1` against `::ffff:c000:0201`. A duplicate check written on the text of an allowlist misses all four, which is how one host gets added twice and removed once. Everything is canonicalised per RFC 5952 — lowercase, leading zeros dropped, the longest run of zero groups collapsed and the leftmost of two equal runs (§4.2.3), a single zero group never collapsed (§4.2.2) — and `sameAddress` compares bytes, with the zone counted because `fe80::1%eth0` and `fe80::1%eth1` are the same bytes on different links (RFC 4007). **The dotted form of a mapped address is kept, and this is the one place the component disagrees with the browser on purpose.** Measured, `new URL("http://[::ffff:192.0.2.1]").hostname` is `[::ffff:c000:201]`: the WHATWG serialiser has no RFC 5952 §5 special case. Both are correct; only one is a string somebody reviewing a firewall rule can recognise. **A prefix written on a mapped address is flagged, and the error is always the same factor.** `::ffff:10.0.0.0/8` is a legal IPv6 block covering 2^120 addresses; the IPv4 `10.0.0.0/8` that was meant is `/104` here, covering 2^24. The ratio does not depend on the prefix — 2^(128−p) over 2^(32−p) is 2^96 for every p — so the mistake is always 79,228,162,514,264,337,593,543,950,336 times, about 7.9e28. **The netmask is assembled a byte at a time, because the one-line version is wrong about the most consequential prefix there is.** Measured, `(0xFFFFFFFF << 32) >>> 0` is `4294967295`, not 0: JavaScript takes a shift count modulo 32, so `prefix` 0 shifts by nothing and `0.0.0.0/0` comes out with a `/32` mask — a firewall UI reading "the entire internet" as "one host". Eight-bit shifts cannot reach 32, so built per byte the failure mode does not exist rather than being guarded against. **The usable count is not "minus two", and that formula produces impossible numbers at both ends of the one family it belongs to.** Measured: `2 ** (32 - 31) - 2` is 0 and `2 ** (32 - 32) - 2` is −1, so it claims a point-to-point link has no usable addresses and a single host has minus one. RFC 3021 makes a /31 a two-address link with both ends usable and a /32 one host. On IPv6 the subtraction is wrong at every prefix, because **there is no broadcast address in IPv6 at all** (RFC 4291 §2.7); what a subnet reserves is the one Subnet-Router anycast address (§2.6.1), and a /127 inter-router link does not reserve even that (RFC 6164). One formula for both families is wrong about one of them everywhere. **The counts are `bigint`, because a /64 is not a Number.** Measured, `2 ** 64` evaluates to 18446744073709552000 where the true value is 18446744073709551616, and `2 ** 64 - 1 === 2 ** 64` is `true` — the commonest IPv6 subnet and the whole of it minus one address are one figure in float64. `Intl.NumberFormat` formats a `bigint` exactly (2^128 comes out as all 39 digits), so nothing has to be narrowed to be shown. **Host bits set in a CIDR is reported with both repairs and neither applied.** `192.168.1.5/24` is a host inside a block, not the block; rounding it down to `192.168.1.0/24` turns a rule about one machine into a rule about 256, which is the distinction the reader was writing the rule to express, so the field offers the network and leaves the /32 alone. **An embedded IPv4 address only reads at the end.** A dotted quad is two groups wherever it sits, so a parser that only counts groups accepts `1.2.3.4::1` and invents an address out of it; measured, `net.isIPv6("1.2.3.4::1")` is `false`, and so is this. **And an empty box is not an address.** Empty parses to nothing and unreadable text parses to a refusal, kept apart because `0.0.0.0` with a `/0` is every host on the internet and a blank allowlist row that posts it is the single most expensive thing this component could do. Accessibility and form behaviour: the field is one `role="group"` with a label, the box is `type="text"` because a number input would discard every character that makes an address, one polite `role="status"` line carries the verdict through `aria-describedby` (two live regions race each other and neither gets read) alongside a second describedby target that is always rendered and sr-only when there is nothing to add, `aria-invalid` and the destructive border both follow the actual fault rather than a non-empty box, a warning leaves both alone because the value still stands, the rewrite controls are `type="button"` so they cannot submit the form they sit in, an sr-only hint names whether a prefix is wanted, and a `name` posts the canonical text plus the family and the prefix through hidden inputs — and posts nothing at all for a value the field would not stand behind. `parseIpText`, `parseLegacyIpv4`, `formatAddress`, `formatCidr`, `sameAddress`, `maskBytes`, `networkBytes`, `lastAddressBytes`, `hostBitsSet`, `addressCount`, `usableCount`, `describePrefix`, `bytesToBigInt`, `bigIntToBytes`, `BITS` and `MAPPED_PREFIX_BITS` are exported as plain functions and values, so the route handler that receives the string reaches the same verdict the field showed instead of carrying a second copy of the rules. `families` and `accept` narrow it to one family or to addresses-only or blocks-only. Official shadcn/ui has nothing of the kind and the measurement is not close: fetching every entry in its registry today — 65 listed, 62 fetchable, `code-block`, `questionnaire` and `trace` 404 on both style tracks — and searching all 223,287 bytes, `ipv4`, `ipv6`, `CIDR`, `subnet`, `netmask`, `inet_aton`, `ip address`, `ipAddress`, `prefixLength` and `octet` are every one of them a zero hit; its `input` is a bare text box and `input-group` only puts ornaments either side of one. Within pulld, `masked-input` fixes the shape of a field whose parts all follow one rule where each half of this one has its own, `number-range-input` is one axis of from-and-to, `latlng-input` is the other two-rules-in-one-field case, and `network-status` reports the browser's own connection rather than taking an address. No dependencies beyond React and your `cn`.
Installation
Requires @pulld in the registries of your components.json (shadcn adds official directory namespaces automatically).
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
Use the "IP Input" component (pulld/ip-input) from its shadcn registry.1. Install it with: npx shadcn@latest add @pulld/ip-input2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.Files & dependencies
- registry/ui/ip-input.tsx
Looks similar, elsewhere
There is no screenshot of this item to compare yet.