How to Install and Use mapcidr in Linux to Parse, Slice, and Aggregate CIDR IP Ranges

Network engineers, cloud architects, and security professionals frequently work with complex subnets, IP ranges, and CIDR blocks (such as 192.168.0.0/16 or 10.0.0.0/8). When planning firewall access control lists (ACLs), configuring route tables, or preparing large target lists for scanning utilities like naabu, nmap, or masscan, you frequently need to expand CIDRs into individual IPs, slice large subnets into smaller equal blocks (such as dividing a /16 into /24 chunks), or aggregate disparate IP lists into minimal CIDR notation. mapcidr, developed by ProjectDiscovery, is an ultra-fast, specialised command-line tool built specifically for this purpose.

Written in Go, mapcidr processes millions of IP addresses and subnet masks in milliseconds through standard Unix pipes, eliminating the need for custom Python scripts or manual subnet calculators.

Core Capabilities of mapcidr

mapcidr provides versatile operations for managing IPv4 and IPv6 address spaces:

  • CIDR Expansion: Expands any subnet mask (e.g., 10.0.0.0/24) into its full list of 256 individual IP addresses.
  • Subnet Slicing: Slices large CIDR blocks into smaller subnets (e.g., dividing a /20 block into sixteen /24 subnets) for distributed network scanning.
  • CIDR Aggregation & Merging: Ingests chaotic, disordered lists of individual IP addresses and merges them into the smallest possible set of consolidated CIDR blocks.
  • Target Shuffling: Randomizes IP address order across subnets to avoid triggering threshold-based firewall port scan alerts.
  • IP Filtering & Inversion: Excludes private RFC 1918 subnets, loopback ranges, or specific client-provided blacklist IPs from target streams.

Installing mapcidr on Linux

You can install mapcidr via pre-compiled GitHub binaries or compile directly using the Go toolchain:

# Method 1: Download Official Pre-compiled Binary (Recommended)
curl -s https://api.github.com/repos/projectdiscovery/mapcidr/releases/latest | grep "browser_download_url.*linux_amd64.tar.gz" | cut -d : -f 2,3 | tr -d \" | wget -qi -
tar -xvf mapcidr_*_linux_amd64.tar.gz
sudo mv mapcidr /usr/local/bin/
mapcidr -version

# Method 2: Via Go (Requires Go 1.21+)
go install -v github.com/projectdiscovery/mapcidr/cmd/mapcidr@latest

Command Flags and Operation Modifiers

The table below summarizes common command-line options in mapcidr:

Flag Functionality Usage Example
-cidr <range> Input CIDR or IP range mapcidr -cidr 192.168.1.0/24
-cl, -cidr-list <file> File containing list of subnets/IPs mapcidr -cl subnets.txt
-silent Output only processed IP/CIDR strings mapcidr -cidr 10.0.0.0/24 -silent
-sbc, -slice-by-cidr <mask> Slices input range into specified subnet masks mapcidr -cidr 10.0.0.0/16 -sbc 24
-a, -aggregate Merges list of IPs into minimal CIDRs mapcidr -cl raw_ips.txt -aggregate
-count Counts total number of host IPs in range mapcidr -cidr 172.16.0.0/12 -count
-filter-ip <range> Excludes specific IPs or ranges from output mapcidr -cl targets.txt -filter-ip 10.0.0.0/8

Practical Workflow Examples

1. Expanding CIDR Blocks into Plain IP Lists

To expand a /24 subnet into all 256 individual host IPs to feed into an active HTTP prober:

mapcidr -cidr 192.168.10.0/24 -silent -o host_ips.txt

2. Aggregating Loose IP Addresses into Minimal CIDRs

If you export thousands of disparate IP addresses from a firewall log or cloud inventory, condense them into minimal clean CIDR blocks:

mapcidr -cl raw_firewall_ips.txt -aggregate -o clean_subnets.txt

3. Slicing Large Enterprise Subnets for Distributed Scanning

Divide a massive /16 network (65,536 hosts) into individual /24 subnets (256 hosts each) to distribute across multiple scanner worker nodes:

mapcidr -cidr 172.16.0.0/16 -slice-by-cidr 24 -o sliced_subnets.txt

4. Automated Pipeline: Subnet Generation to Fast Port Scanning

Slice subnets and immediately pipe them into Naabu for high-speed port scanning:

echo "192.168.1.0/24" | mapcidr -silent | naabu -top-ports 100 -silent -o active_ports.txt

Frequently Asked Questions

Does mapcidr support IPv6 addresses?

Yes. mapcidr supports standard IPv6 CIDR notation (such as 2001:db8::/32) and can perform subnet expansion and aggregation across IPv6 spaces.

Can mapcidr handle hyphenated IP ranges (e.g., 192.168.1.1-192.168.1.50)?

Yes. In addition to standard CIDR notation, mapcidr parses dash-separated IP ranges (192.168.1.1-192.168.1.50) and converts them into normalized CIDR blocks or expanded lists.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.