{"id":"cidr-math","title":"CIDR math: IPv4 and IPv6 overlap, adjacency, merge, subtract, membership","description":"Computes exact CIDR relations for agents planning networks, firewall rules or allow-lists: for up to 200 IPv4/IPv6 blocks it reports which pairs are equal, nested, partially overlapping or merely adjacent, the minimal merged CIDR list, a subtraction (blocks minus exclusions), address membership with the most specific match, or each block's first/last address, count and host-bits-set errors. It does not resolve hostnames, look up ownership or routing, interpret IPv6 zone ids, or decide whether an overlap is intentional; IPv4-mapped IPv6 stays a separate family unless normalizeMapped is true.","roi":"Subnet overlap and off-by-one boundary mistakes in firewall and VPC plans are exact arithmetic; one call replaces a hand calculation.","audience":"developer","package":"infra-preflight-kit","channels":["x402","mcp"],"endpoint":{"method":"POST","url":"https://agents.writerslogic.com/api/v1/cidr-math","path":"/api/v1/cidr-math","contentType":"application/json"},"price":{"amount":"0.005","currency":"USDC","network":"base","perCall":true,"failedCallsCharged":false},"inputSchema":{"type":"object","additionalProperties":false,"required":["op","ranges"],"properties":{"op":{"type":"string","enum":["inspect","relations","merge","subtract","contains"],"description":"inspect: normalize each range and flag host bits set. relations: pairwise equal/contains/overlap/adjacent/disjoint (pass only when no two ranges intersect). merge: minimal CIDR cover of the union. subtract: ranges minus exclude. contains: which ranges contain each address (pass only when every address is covered)."},"ranges":{"type":"array","minItems":1,"maxItems":200,"items":{"type":"string","maxLength":100},"description":"CIDR (10.0.0.0/8, 2001:db8::/32), a bare address (a /32 or /128), or an inclusive range 10.0.0.1-10.0.0.9."},"exclude":{"type":"array","maxItems":200,"items":{"type":"string","maxLength":100},"description":"Only for op=subtract."},"addresses":{"type":"array","maxItems":500,"items":{"type":"string","maxLength":64},"description":"Only for op=contains."},"normalizeMapped":{"type":"boolean","description":"Treat ::ffff:a.b.c.d (and prefixes of 96 bits or longer inside ::ffff:0:0/96) as the IPv4 block a.b.c.d. Default false."}}},"resultSchema":{"type":"object","properties":{"status":{"type":"string","enum":["pass","fail","unknown","unsupported"],"description":"pass: every rule held. fail: a rule was violated (see witnesses). unknown: the input lacks the evidence to decide. unsupported: outside what this engine covers. Missing evidence is never a pass."},"op":{"type":"string"},"ranges":{"type":"array","items":{"type":"object","properties":{"input":{"type":"string"},"error":{"type":"string"},"family":{"type":"integer"},"cidr":{"type":"string","description":"Minimal CIDR cover (several blocks when the input is not CIDR-aligned); the first 16 blocks when there are more."},"cidrBlocks":{"type":"integer","description":"Number of blocks in the full minimal cover."},"first":{"type":"string"},"last":{"type":"string"},"count":{"type":"string","description":"Decimal address count (exceeds 2^53 for IPv6)."},"kind":{"type":"string","enum":["host","cidr","range"]},"canonical":{"type":"boolean","description":"false when a CIDR had host bits set; it was masked to its network address."},"ipv4Mapped":{"type":"boolean"}}}},"pairs":{"type":"array","items":{"type":"object","properties":{"a":{"type":"integer"},"b":{"type":"integer"},"relation":{"type":"string"}}},"description":"relations: every non-disjoint pair (adjacent included) by range index."},"cidrs":{"type":"array","items":{"type":"string"},"description":"merge/subtract: resulting CIDR blocks in address order."},"matches":{"type":"array","items":{"type":"object","properties":{"address":{"type":"string"},"rangeIndexes":{"type":"array","items":{"type":"integer"}},"mostSpecific":{"type":"integer","description":"Index of the smallest containing range, -1 if none."}}}},"total":{"type":"integer","description":"Number of CIDR blocks before truncation."},"truncated":{"type":"boolean"},"witnesses":{"type":"array","items":{"type":"object","properties":{"ruleId":{"type":"string"},"detail":{"type":"string"},"path":{"type":"string","description":"JSON pointer or dotted path into the input."},"offset":{"type":"integer"},"index":{"type":"integer"},"expected":{"description":"What the rule required."},"actual":{"description":"What the input had."}}}},"versions":{"type":"object","description":"Every semantic dependency of this answer (engine, tables and their as-of dates, tokenizer, calendar, rounding profile)."},"limits":{"type":"array","items":{"type":"string"}},"deterministic":{"type":"boolean","description":"Always true: pure code, no model."}}},"outputSchema":{"type":"object","properties":{"data":{"type":"object","properties":{"status":{"type":"string","enum":["pass","fail","unknown","unsupported"],"description":"pass: every rule held. fail: a rule was violated (see witnesses). unknown: the input lacks the evidence to decide. unsupported: outside what this engine covers. Missing evidence is never a pass."},"op":{"type":"string"},"ranges":{"type":"array","items":{"type":"object","properties":{"input":{"type":"string"},"error":{"type":"string"},"family":{"type":"integer"},"cidr":{"type":"string","description":"Minimal CIDR cover (several blocks when the input is not CIDR-aligned); the first 16 blocks when there are more."},"cidrBlocks":{"type":"integer","description":"Number of blocks in the full minimal cover."},"first":{"type":"string"},"last":{"type":"string"},"count":{"type":"string","description":"Decimal address count (exceeds 2^53 for IPv6)."},"kind":{"type":"string","enum":["host","cidr","range"]},"canonical":{"type":"boolean","description":"false when a CIDR had host bits set; it was masked to its network address."},"ipv4Mapped":{"type":"boolean"}}}},"pairs":{"type":"array","items":{"type":"object","properties":{"a":{"type":"integer"},"b":{"type":"integer"},"relation":{"type":"string"}}},"description":"relations: every non-disjoint pair (adjacent included) by range index."},"cidrs":{"type":"array","items":{"type":"string"},"description":"merge/subtract: resulting CIDR blocks in address order."},"matches":{"type":"array","items":{"type":"object","properties":{"address":{"type":"string"},"rangeIndexes":{"type":"array","items":{"type":"integer"}},"mostSpecific":{"type":"integer","description":"Index of the smallest containing range, -1 if none."}}}},"total":{"type":"integer","description":"Number of CIDR blocks before truncation."},"truncated":{"type":"boolean"},"witnesses":{"type":"array","items":{"type":"object","properties":{"ruleId":{"type":"string"},"detail":{"type":"string"},"path":{"type":"string","description":"JSON pointer or dotted path into the input."},"offset":{"type":"integer"},"index":{"type":"integer"},"expected":{"description":"What the rule required."},"actual":{"description":"What the input had."}}}},"versions":{"type":"object","description":"Every semantic dependency of this answer (engine, tables and their as-of dates, tokenizer, calendar, rounding profile)."},"limits":{"type":"array","items":{"type":"string"}},"deterministic":{"type":"boolean","description":"Always true: pure code, no model."}}},"_provenance":{"type":"object","description":"C2PA-aligned manifest and W3C VC 2.0 (eddsa-jcs-2022) issued by the hub DID; verify at POST /api/v1/verify-provenance"}},"required":["data","_provenance"]},"example":{"op":"relations","ranges":["10.0.0.0/24","10.0.1.0/24","10.0.0.128/25","2001:db8::/32"]},"openapiOperation":{"operationId":"cidr_math","summary":"CIDR math: IPv4 and IPv6 overlap, adjacency, merge, subtract, membership","description":"Computes exact CIDR relations for agents planning networks, firewall rules or allow-lists: for up to 200 IPv4/IPv6 blocks it reports which pairs are equal, nested, partially overlapping or merely adjacent, the minimal merged CIDR list, a subtraction (blocks minus exclusions), address membership with the most specific match, or each block's first/last address, count and host-bits-set errors. It does not resolve hostnames, look up ownership or routing, interpret IPv6 zone ids, or decide whether an overlap is intentional; IPv4-mapped IPv6 stays a separate family unless normalizeMapped is true.\n\nPrice: 0.005 USDC on Base (x402).","x-x402-price-usdc":"0.005","x-x402-amount":"5000","x-payment-info":{"protocols":["x402"],"price":{"mode":"fixed","currency":"USD","amount":"0.005"}},"x-audience":"developer","x-sample-url":"https://agents.writerslogic.com/api/v1/samples/cidr-math","security":[{"x402":[]},{"apiKey":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":false,"required":["op","ranges"],"properties":{"op":{"type":"string","enum":["inspect","relations","merge","subtract","contains"],"description":"inspect: normalize each range and flag host bits set. relations: pairwise equal/contains/overlap/adjacent/disjoint (pass only when no two ranges intersect). merge: minimal CIDR cover of the union. subtract: ranges minus exclude. contains: which ranges contain each address (pass only when every address is covered)."},"ranges":{"type":"array","minItems":1,"maxItems":200,"items":{"type":"string","maxLength":100},"description":"CIDR (10.0.0.0/8, 2001:db8::/32), a bare address (a /32 or /128), or an inclusive range 10.0.0.1-10.0.0.9."},"exclude":{"type":"array","maxItems":200,"items":{"type":"string","maxLength":100},"description":"Only for op=subtract."},"addresses":{"type":"array","maxItems":500,"items":{"type":"string","maxLength":64},"description":"Only for op=contains."},"normalizeMapped":{"type":"boolean","description":"Treat ::ffff:a.b.c.d (and prefixes of 96 bits or longer inside ::ffff:0:0/96) as the IPv4 block a.b.c.d. Default false."}}},"example":{"op":"relations","ranges":["10.0.0.0/24","10.0.1.0/24","10.0.0.128/25","2001:db8::/32"]}}}},"responses":{"200":{"description":"Paid result with provenance","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object","properties":{"status":{"type":"string","enum":["pass","fail","unknown","unsupported"],"description":"pass: every rule held. fail: a rule was violated (see witnesses). unknown: the input lacks the evidence to decide. unsupported: outside what this engine covers. Missing evidence is never a pass."},"op":{"type":"string"},"ranges":{"type":"array","items":{"type":"object","properties":{"input":{"type":"string"},"error":{"type":"string"},"family":{"type":"integer"},"cidr":{"type":"string","description":"Minimal CIDR cover (several blocks when the input is not CIDR-aligned); the first 16 blocks when there are more."},"cidrBlocks":{"type":"integer","description":"Number of blocks in the full minimal cover."},"first":{"type":"string"},"last":{"type":"string"},"count":{"type":"string","description":"Decimal address count (exceeds 2^53 for IPv6)."},"kind":{"type":"string","enum":["host","cidr","range"]},"canonical":{"type":"boolean","description":"false when a CIDR had host bits set; it was masked to its network address."},"ipv4Mapped":{"type":"boolean"}}}},"pairs":{"type":"array","items":{"type":"object","properties":{"a":{"type":"integer"},"b":{"type":"integer"},"relation":{"type":"string"}}},"description":"relations: every non-disjoint pair (adjacent included) by range index."},"cidrs":{"type":"array","items":{"type":"string"},"description":"merge/subtract: resulting CIDR blocks in address order."},"matches":{"type":"array","items":{"type":"object","properties":{"address":{"type":"string"},"rangeIndexes":{"type":"array","items":{"type":"integer"}},"mostSpecific":{"type":"integer","description":"Index of the smallest containing range, -1 if none."}}}},"total":{"type":"integer","description":"Number of CIDR blocks before truncation."},"truncated":{"type":"boolean"},"witnesses":{"type":"array","items":{"type":"object","properties":{"ruleId":{"type":"string"},"detail":{"type":"string"},"path":{"type":"string","description":"JSON pointer or dotted path into the input."},"offset":{"type":"integer"},"index":{"type":"integer"},"expected":{"description":"What the rule required."},"actual":{"description":"What the input had."}}}},"versions":{"type":"object","description":"Every semantic dependency of this answer (engine, tables and their as-of dates, tokenizer, calendar, rounding profile)."},"limits":{"type":"array","items":{"type":"string"}},"deterministic":{"type":"boolean","description":"Always true: pure code, no model."}}},"_provenance":{"type":"object","description":"C2PA-aligned manifest and W3C VC 2.0 (eddsa-jcs-2022) issued by the hub DID; verify at POST /api/v1/verify-provenance"}},"required":["data","_provenance"]}}}},"400":{"description":"Invalid request (no payment consumed)","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"code":{"type":"string"}}}}}},"401":{"description":"Invalid X-API-KEY","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"code":{"type":"string"}}}}}},"402":{"description":"Payment required or invalid","content":{"application/json":{"schema":{"type":"object","description":"x402 v2 PaymentRequired (also base64 in the PAYMENT-REQUIRED header)","properties":{"x402Version":{"type":"integer"},"error":{"type":"string"},"code":{"type":"string"},"resource":{"type":"object"},"accepts":{"type":"array","items":{"type":"object"}},"extensions":{"type":"object"}}}}}},"502":{"description":"Upstream failure; the payment is released or not settled","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"code":{"type":"string"}}}}}}}},"links":{"docs":"https://agents.writerslogic.com/docs/cidr-math/","docsJson":"https://agents.writerslogic.com/docs/cidr-math.json","sample":"https://agents.writerslogic.com/api/v1/samples/cidr-math","openapi":"https://agents.writerslogic.com/openapi.json","catalog":"https://agents.writerslogic.com/api/v1/catalog","verifyProvenance":"https://agents.writerslogic.com/api/v1/verify-provenance","index":"https://agents.writerslogic.com/docs/index.json"}}