Expand CIDR Range API: The Complete Guide

Need to list all IP addresses in a network range? This guide covers everything about expanding CIDR notation via API, including handling large ranges, pagination, and implementation examples.

What is CIDR Expansion?

CIDR expansion converts a compact network notation like 192.168.1.0/24 into a complete list of all IP addresses in that range. A /24 network contains 256 addresses (from .0 to .255).

This is useful for scanning, inventory, whitelisting, and other operations that need explicit IP addresses.

Handling Large Ranges

Network sizes vary dramatically:

  • /32 = 1 IP
  • /24 = 256 IPs
  • /16 = 65,536 IPs
  • /8 = 16,777,216 IPs
Warning: Expanding large ranges (smaller than /20) can produce millions of IPs. The API limits expansion to /20 or smaller to prevent resource exhaustion. Use pagination for manageable chunks.

Using the Expand CIDR API

TinyFn provides an endpoint for CIDR expansion with pagination:

API Request
GET https://api.tinyfn.io/v1/ip/expand-cidr?cidr=192.168.1.0/28
Headers: X-API-Key: your-api-key
Response
{
  "cidr": "192.168.1.0/28",
  "total_addresses": 16,
  "ips": [
    "192.168.1.0",
    "192.168.1.1",
    "192.168.1.2",
    "192.168.1.3",
    "192.168.1.4",
    "192.168.1.5",
    "192.168.1.6",
    "192.168.1.7",
    "192.168.1.8",
    "192.168.1.9",
    "192.168.1.10",
    "192.168.1.11",
    "192.168.1.12",
    "192.168.1.13",
    "192.168.1.14",
    "192.168.1.15"
  ],
  "first_ip": "192.168.1.0",
  "last_ip": "192.168.1.15"
}

Parameters

Parameter Type Description
cidr string Network in CIDR notation (required, /20 or larger prefix)
offset integer Starting index for pagination (default: 0)
limit integer Maximum IPs to return (default: 1000, max: 10000)
exclude_network boolean Exclude network address (default: false)
exclude_broadcast boolean Exclude broadcast address (default: false)

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/ip/expand-cidr?cidr=192.168.1.0/28',
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const { ips, total_addresses } = await response.json();
console.log(`Total: ${total_addresses} IPs`);
ips.forEach(ip => console.log(ip));

Python

import requests

response = requests.get(
    'https://api.tinyfn.io/v1/ip/expand-cidr',
    headers={'X-API-Key': 'your-api-key'},
    params={'cidr': '192.168.1.0/28'}
)
data = response.json()
print(f"Total: {data['total_addresses']} IPs")
for ip in data['ips']:
    print(ip)

cURL

curl "https://api.tinyfn.io/v1/ip/expand-cidr?cidr=192.168.1.0/28" \
  -H "X-API-Key: your-api-key"

Common Use Cases

  • Network Scanning: Generate target list for security scans
  • IP Whitelisting: Populate firewall rules from CIDR notation
  • Inventory Management: Track all IPs in allocated ranges
  • DNS Configuration: Generate reverse DNS entries
  • Monitoring Setup: Configure monitoring for all network hosts

Best Practices

  1. Use pagination: Process large ranges in chunks to manage memory
  2. Exclude special addresses: Often network and broadcast aren't needed
  3. Validate CIDR first: Ensure the CIDR is valid before expansion
  4. Consider alternatives: For very large ranges, iterate mathematically instead

Try the Expand CIDR API

Get your free API key and start expanding CIDR ranges in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key