Install mapCIDR
mainInstall the mapCIDR CLI tool using go install from the latest version on GitHub.
go install -v github.com/projectdiscovery/mapcidr/cmd/mapcidr@latestrepository·main·Indexed 22 days ago
https://github.com/projectdiscovery/mapcidrA high-performance utility and Go library for subnet operations, including CIDR expansion, slicing by CIDR or host count, aggregation, and IP filtering. It supports converting between IPv4 and IPv6, transforming IPs into various formats (hex, decimal, binary, etc.), and calculating host counts. Designed to facilitate load distribution for mass scanning operations, it provides both a CLI tool and a Go package with functions like SplitN, SplitByNumber, and CoalesceCIDRs.
Install the mapCIDR CLI tool using go install from the latest version on GitHub.
go install -v github.com/projectdiscovery/mapcidr/cmd/mapcidr@latestUse the -count flag to return the total number of IP addresses within a given CIDR or list of CIDRs.
echo 173.0.84.0/16 | mapcidr -count -silentUse -ip-format or -if to display IPs in various formats. Passing 0 to -if will display all 10 supported unique formats (e.g., hex, decimal, binary, etc.).
echo 127.0.1.0 | mapcidr -if 0 -silent192.168.0.0-192.168.0.5) via STDIN.-mi (match-ip) to only output IPs from the input CIDR that exist in the provided match list. Use -fi (filter-ip) to exclude IPs from the input CIDR that exist in the provided filter list. Both flags accept comma-separated strings or file paths.Use the -sbh flag to slice a CIDR into multiple subnets, each containing approximately the specified number of hosts. The tool attempts to find the best split strategy if a perfect power-of-two split is not possible.
mapcidr -cidr 173.0.84.0/16 -sbh 20000 -silentUse the -sbc flag to slice a CIDR (or a list of CIDRs) into a specific number of smaller, equal subnets. Use -silent to suppress the banner and warnings.
mapcidr -cidr 173.0.84.0/24 -sbc 10 -silent-t4 or convert IPv4 addresses to IPv6 notation using -t6. Note that not all IPv6 addresses can be converted to IPv4; only valid IPv4-represented IPv6 addresses are supported.Aggregate multiple CIDR ranges or individual IPs into the minimum possible subnet blocks using -a or -aggregate.
For sparse IP groups (IPv4 only), use -aa or -aggregate-approx to perform approximated aggregation, which may result in a final interval containing contiguous IPs that were not in the original input.
mapCIDR supports authentication with ProjectDiscovery Cloud (PDCP). Authentication follows this hierarchy:
--auth CLI flag (if set to true, it triggers credential validation).PDCP_API_KEY environment variable..pdcp/credential file.If you provide a 36-character string via the --auth flag, it is treated as the API key. If no local credentials exist, the tool will attempt to validate the key against the PDCP API server (configured via PDCP_API_SERVER) and save it if valid.
mapCIDR is a tool designed to ease load distribution for mass scanning operations. It can process CIDRs, individual IPs, IP ranges, and ASNs. It supports various operations including slicing, aggregation, filtering, and format conversion.
Input Methods:
-cidr or -cl flag to provide a list of CIDRs/IPs or a file containing them.stdin.Common Operations:
-sbc (by CIDR count) or -sbh (by host count).-aggregate or approximated subnets using -aggregate-approx.-f4) or IPv6 (-f6), or use -match-ip to include only specific IPs/CIDRs or -filter-ip to exclude them.-range), or convert IPs to IPv4 (-t4) or IPv6 (-t6) formats.You can import github.com/projectdiscovery/mapcidr to use its core functionality directly in your Go applications. Key functions include SplitN for slicing by CIDR count, SplitByNumber for slicing by host count, and IPAddresses to list all IPs in a CIDR.
package main
import (
"fmt"
"github.com/projectdiscovery/mapcidr"
)
func main() {
// Divide the CIDR into two subnets
subnets1 := mapcidr.SplitN("192.168.1.0/24", 2)
for _, subnet := range subnets1 {
fmt.Println(subnet)
}
// Divide the CIDR into two subnets containing 128 hosts each
subnets2 := mapcidr.SplitByNumber("192.168.1.0/24", 128)
for _, subnet := range subnets2 {
fmt.Println(subnet)
}
// List all IPs in the CIDR
ips, _ := mapcidr.IPAddresses("192.168.1.0/24")
for _, ip := range ips {
fmt.Println(ip)
}
}