MapCIDR is a small utility program to perform multiple operations for a given subnet/CIDR ranges.
The tool was developed to ease load distribution for mass scanning operations, it can be used both as a library and as independent CLI tool.
Features
Installation
▶ GO111MODULE=auto go get -u github.com/projectdiscovery/mapcidr/cmd/mapcidr
▶ git clone https://github.com/projectdiscovery/mapcidr.git; cd mapcidr/cmd/mapcidr; go build .; cp mapcidr /usr/local/bin
Usage
▶ mapcidr -h
This will display help for the tool. Here are all the switches it supports.
Flag | Description | Example |
---|---|---|
-cidr | Single CIDR to process | mapcidr -cidr 173.0.84.0/24 |
-sbc | Slice by CIDR count | mapcidr -sbc 10 |
-sbh | Slice by HOST count | mapcidr -sbh 10000 |
-l | File containing list of CIDRs | mapcidr -l cidr.txt |
-o | File to write output to (optional) | mapcidr -o output.txt |
-silent | Make the output silent | mapcidr -silent |
-version | Print current version of mapcidr client | mapcidr -version |
Running mapCIDR
In order to get list of IPs for a give CIDR, use the following command.
▶ mapcidr -cidr 173.0.84.0/24
▶ echo 173.0.84.0/24 | mapcidr
Slice by CIDR
In order to slice given CIDR or list of CIDR by CIDR count or slice into multiple and equal smaller subnets, use the following command.
▶ mapcidr -cidr 173.0.84.0/24 -sbc 10 -silent
▶ echo 173.0.84.0/24 | mapcidr -sbc 10 -silent
Slice by HOST
In order to slice given CIDR for equal number of host count in each CIDR, use the following command.
▶ mapcidr -cidr 173.0.84.0/16 -sbh 20000 -silent
▶ echo 173.0.84.0/16 | mapcidr -sbh 20000 -silent
Note: it’s possible to obtain a perfect split only when the desired amount of slices or hosts per subnet is a powers of two. Otherwise the tool will attempt to automatically find the best split strategy to obtain the desired outcome.
Use mapCIDR as a library
It’s possible to use the library directly in your go programs. The following code snippets outline how to divide a cidr into subnets, and how to divide the same into subnets containing a certain number of hosts
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.Ips(“192.168.1.0/24”)
for _, ip := range ips {
fmt.Println(ip)
}
}
mapCDIR is made with 🖤 by the projectdiscovery team.
Introduction In cybersecurity and IT operations, logging fundamentals form the backbone of monitoring, forensics, and…
What is Networking? Networking brings together devices like computers, servers, routers, and switches so they…
Introduction In the world of Open Source Intelligence (OSINT), anonymity and operational security (OPSEC) are…
Introduction As cyber threats grow more sophisticated, organizations need more than just firewalls and antivirus…
Introduction When it comes to cybersecurity and ethical hacking, one of the most effective ways…
Introduction In the world of cybersecurity, knowledge is power. One of the most powerful skillsets…