• Stars
    star
    811
  • Rank 53,951 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 3 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Small utility program to perform multiple operations for a given subnet/CIDR ranges.

mapCIDR

A utility program to perform multiple operations for a given subnet/cidr ranges.

Features β€’ Install β€’ Usage β€’ Library β€’ Join Discord


mapCIDR is developed to ease load distribution for mass scanning operations, it can be used both as a library and as independent CLI tool.

Features

mapCIDR

  • CIDR expansion support (default)
  • CIDR slicing support (sbh, sbc)
  • CIDR/IP aggregation support (a, aa)
  • CIDR/IP matcher support (match-ip)
  • CIDR/IP filter support (filter-ip)
  • CIDR/IP sorting support (s, sr)
  • CIDR host count support (count)
  • Multiple IP Format support (ip-format)
  • IP/PORT shuffling support (si, sp)
  • IPv4/IPv6 Conversation support (t4, t6)
  • CIDR STDIN (pipe) input support

Installation

go install -v github.com/projectdiscovery/mapcidr/cmd/mapcidr@latest

Usage

mapcidr -h

This will display help for the tool. Here are all the switches it supports.

INPUT:
   -cl, -cidr string[]  CIDR/IP/File containing list of CIDR/IP to process

PROCESS:
   -sbc int                  Slice CIDRs by given CIDR count
   -sbh int                  Slice CIDRs by given HOST count
   -a, -aggregate            Aggregate IPs/CIDRs into minimum subnet
   -aa, -aggregate-approx    Aggregate sparse IPs/CIDRs into minimum approximated subnet
   -c, -count                Count number of IPs in given CIDR
   -t4, -to-ipv4             Convert IPs to IPv4 format
   -t6, -to-ipv6             Convert IPs to IPv6 format
   -ip-format, -if string[]  IP formats (0,1,2,3,4,5,6,7,8,9,10,11)
   -zpn, -zero-pad-n int     number of padded zero to use (default 3)
   -zpp, -zero-pad-permute   enable permutations from 0 to zero-pad-n for each octets

FILTER:
   -f4, -filter-ipv4         Filter IPv4 IPs from input
   -f6, -filter-ipv6         Filter IPv6 IPs from input
   -skip-base                Skip base IPs (ending in .0) in output
   -skip-broadcast           Skip broadcast IPs (ending in .255) in output
   -mi, -match-ip string[]   IP/CIDR/FILE containing list of IP/CIDR to match (comma-separated, file input)
   -fi, -filter-ip string[]  IP/CIDR/FILE containing list of IP/CIDR to filter (comma-separated, file input)

MISCELLANEOUS:
   -s, -sort                  Sort input IPs/CIDRs in ascending order
   -sr, -sort-reverse         Sort input IPs/CIDRs in descending order
   -si, -shuffle-ip           Shuffle Input IPs in random order
   -sp, -shuffle-port string  Shuffle Input IP:Port in random order

UPDATE:
   -up, -update                 update mapcidr to latest version
   -duc, -disable-update-check  disable automatic mapcidr update check
   
OUTPUT:
   -verbose            Verbose mode
   -o, -output string  File to write output to
   -silent             Silent mode
   -version            Show version of the project

Running mapCIDR

In order to get list of IPs for a give CIDR, use the following command.

CIDR expansion

mapcidr -cidr 173.0.84.0/24
                   ____________  ___    
  __ _  ___ ____  / ___/  _/ _ \/ _ \
 /  ' \/ _ '/ _ \/ /___/ // // / , _/   
/_/_/_/\_,_/ .__/\___/___/____/_/|_| v0.5
          /_/                                                     	 

		projectdiscovery.io

[WRN] Use with caution. You are responsible for your actions
[WRN] Developers assume no liability and are not responsible for any misuse or damage.

173.0.84.0
173.0.84.1
173.0.84.2
173.0.84.3
173.0.84.4
173.0.84.5
173.0.84.13
173.0.84.14
173.0.84.15
173.0.84.16

It is also possible to get list of IP's for a given IP range, use the following command

$ echo "192.168.0.0-192.168.0.5" | mapcidr
192.168.0.0
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.4
192.168.0.5

CIDR Slicing by CIDR Count

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
173.0.84.0/27
173.0.84.32/27
173.0.84.64/27
173.0.84.96/27
173.0.84.128/27
173.0.84.160/27
173.0.84.208/28
173.0.84.192/28
173.0.84.240/28
173.0.84.224/28

CIDR slicing by HOST Count

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
173.0.0.0/18
173.0.64.0/18
173.0.128.0/18
173.0.192.0/18

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.

CIDR/IP Aggregation

In order to merge multiple CIDR ranges into smaller subnet block, use the following command.

$ mapcidr -cl cidrs.txt -aggregate

In order to list CIDR blocks for given list of IPs, use the following command.

$ mapcidr -il ips.txt -aggregate

It's also possible to perform approximated aggregations for sparse ips groups (only version 4). The final interval will contain contiguous ips not belonging to the input:

$ cat ips.txt 

1.1.1.1
1.1.1.16
1.1.1.31
$ cat ips.txt | mapcidr -aggregate-approx

1.1.1.0/27

In order to list CIDR blocks for given IP Range (IPv4 | IPv6), use the following command.

 $ mapcidr  -cl 192.168.0.1-192.168.0.255 -aggregate
 OR
 $ echo 192.168.0.1-192.168.0.255 | mapcidr -aggregate
192.168.0.1/32
192.168.0.2/31
192.168.0.4/30
192.168.0.8/29
192.168.0.16/28
192.168.0.32/27
192.168.0.64/26
192.168.0.128/25

Match / Filter IP's from CIDR

In order to match IPs from the given list of CIDR ranges, use the following command.

$ mapcidr -cidr 192.168.1.0/24 -mi 192.168.1.253,192.168.1.252
$ mapcidr -cidr 192.168.1.0/24 -mi ip_list_to_match.txt

In order to match IPs from the given list of CIDR ranges, use the following command.

$ mapcidr -cidr 192.168.1.224/28 -fi 192.168.1.233,192.168.1.234
$ mapcidr -cidr 192.168.1.224/28 -fi ip_list_to_filter.txt

IP Formats

In order to represent given IP into multiple formats, -if 0 flag can be used to display all the supported format values, and specific type of format can be displayed using specific index number as listed here, currently 10 unique formats are supported.

$ echo 127.0.1.0 | mapcidr -if 0 -silent

127.0.1.0
127.1
0177.0.01.0
0x7f.0x0.0x1.0x0
0x7f000100
0xabfa659dfa7f000100
281472812450048
111111111111111101111111000000000000000100000000
0x7f.0.01.0x0
::ffff:7f00:0100
%31%32%37%2E%30%2E%31%2E%30
127.000.001.000

IP Conversion

IPv4 | IPv6 addresses can be converted from either the v6 to v4 notation or IPv4-mapped notation into IPv4 addresses using -t4 and -t6 to IPv4 and IPv6 respectively.

$ cat ips.txt 

1.1.1.1
2.2.2.2
$ mapcidr -cl ips.txt -t6

00:00:00:00:00:ffff:0101:0101
00:00:00:00:00:ffff:0202:0202

Note:

Not all IPv6 address can be converted to IPv4. You can only convert valid IPv4 represented IPv6 addresses.

CIDR Host Counting

In order to count number of hosts for a given CIDR or list of CIDR, use the following command.

$ echo 173.0.84.0/16 | mapcidr -count -silent

65536

ASN Input

In order to get the IP address of ASN number, use the following command

echo AS15133 | mapcidr -silent

5.104.64.0
5.104.64.1
5.104.64.2
5.104.64.3
5.104.64.4

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.IPAddresses("192.168.1.0/24")
	for _, ip := range ips {
		fmt.Println(ip)
	}
}

mapCDIR is made with πŸ–€ by the projectdiscovery team.

More Repositories

1

nuclei

Fast and customizable vulnerability scanner based on simple YAML based DSL.
Go
14,482
star
2

subfinder

Fast passive subdomain enumeration tool.
Go
9,100
star
3

katana

A next-generation crawling and spidering framework.
Go
8,492
star
4

nuclei-templates

Community curated list of templates for the nuclei engine to find security vulnerabilities.
6,913
star
5

httpx

httpx is a fast and multi-purpose HTTP toolkit that allows running multiple probes using the retryablehttp library.
Go
5,706
star
6

naabu

A fast port scanner written in go with a focus on reliability and simplicity. Designed to be used in combination with other tools for attack surface discovery in bug bounties and pentests
Go
3,657
star
7

interactsh

An OOB interaction gathering server and client library
Go
2,818
star
8

proxify

A versatile and portable proxy for capturing, manipulating, and replaying HTTP/HTTPS traffic on the go.
Go
2,362
star
9

uncover

Quickly discover exposed hosts on the internet using multiple search engines.
Go
2,026
star
10

dnsx

dnsx is a fast and multi-purpose DNS toolkit allow to run multiple DNS queries of your choice with a list of user-supplied resolvers.
Go
1,708
star
11

shuffledns

MassDNS wrapper written in go that allows you to enumerate valid subdomains using active bruteforce as well as resolve subdomains with wildcard handling and easy input-output support.
Go
1,119
star
12

nuclei-burp-plugin

Nuclei plugin for BurpSuite
Java
1,042
star
13

notify

Notify is a Go-based assistance package that enables you to stream the output of several tools (or read from a file) and publish it to a variety of supported platforms.
Go
951
star
14

public-bugbounty-programs

Community curated list of public bug bounty and responsible disclosure programs.
Go
876
star
15

cloudlist

Cloudlist is a tool for listing Assets from multiple Cloud Providers.
Go
691
star
16

fuzzing-templates

Community curated list of nuclei templates for finding "unknown" security vulnerabilities.
668
star
17

tlsx

Fast and configurable TLS grabber focused on TLS based data collection.
Go
654
star
18

pdtm

ProjectDiscovery's Open Source Tool Manager
Go
521
star
19

asnmap

Go CLI and Library for quickly mapping organization network ranges using ASN information.
Go
516
star
20

wappalyzergo

A high performance go implementation of Wappalyzer Technology Detection Library
Go
498
star
21

chaos-client

Go client to communicate with Chaos DB API.
Go
498
star
22

alterx

Fast and customizable subdomain wordlist generator using DSL
Go
480
star
23

cdncheck

A utility to detect various technology for a given IP address.
Go
463
star
24

simplehttpserver

Go alternative of python SimpleHTTPServer
Go
418
star
25

nuclei-ai-extension

Nuclei AI - Browser Extension for Rapid Nuclei Template Generation
JavaScript
351
star
26

dnsprobe

DNSProb is a tool built on top of retryabledns that allows you to perform multiple dns queries of your choice with a list of user supplied resolvers.
Go
269
star
27

aix

AIx is a cli tool to interact with Large Language Models (LLM) APIs.
Go
200
star
28

nuclei-action

Vulnerability Scan with Nuclei
JavaScript
199
star
29

interactsh-web

Web dashboard for Interactsh client
TypeScript
162
star
30

openrisk

openrisk is a tool that generates a risk score based on the results of a Nuclei scan.
Go
156
star
31

rawhttp

Raw HTTP client in Go for complete request control and customization.
Go
120
star
32

retryabledns

Retryable DNS client in Go
Go
103
star
33

retryablehttp-go

Package retryablehttp provides a familiar HTTP client interface with automatic retries and exponential backoff
Go
92
star
34

nuclei-docs

Nuclei documentation
HTML
84
star
35

gologger

A simple layer for leveled logging in go
Go
66
star
36

utils

Helper Libraries
Go
65
star
37

network-fingerprint

A fingerprint generation helper for nuclei network templates
Go
61
star
38

goflags

A go flag wrapper with convenience helpers
Go
59
star
39

awesome-search-queries

Community curated list of search queries for various products across multiple search engines.
46
star
40

fastdialer

Dialer with DNS Cache + Dial History
Go
45
star
41

ipranger

IP/FQDN data structure helper with randomization of hosts and ports based on masscan internal logic
Go
43
star
42

dsl

DSL engine
Go
38
star
43

hmap

Hybrid memory/disk map
Go
35
star
44

useragent

Curated list of categorized User Agents
Go
30
star
45

wallpapers

Collection of ProjectDiscovery wallpapers
26
star
46

collaborator

BurpSuite Standard/Private Collaborator Library
Go
22
star
47

tinydns

Tiny embeddable dns server
Go
22
star
48

blackrock

blackrock cipher based on masscan
Go
21
star
49

fdmax

Small Helper Library to increase automatically the file descriptors limits for the current process
Go
21
star
50

ratelimit

A Golang blocking rate limit implementation
Go
20
star
51

php-app-race-condition

Vulnerable demo application for the race condition
PHP
17
star
52

yamldoc-go

A documentation generator for YAML as code
Go
16
star
53

freeport

Free listening port from the OS
Go
16
star
54

clistats

A command based package for simple display of statistics
Go
15
star
55

sqlc-go-builder

sqlc-go-builder
Go
13
star
56

notify-action

Notify is a helper utility written in Go that allows you to post output to multiple platforms.
12
star
57

naabu-action

A fast port scanner written in go with a focus on reliability and simplicity.
12
star
58

fileutil

File helpers - Moved at https://github.com/projectdiscovery/utils
Go
12
star
59

subfinder-action

Fast and passive subdomain enumeration.
12
star
60

roundrobin

roundrobin with configurable rotating strategies
Go
11
star
61

executil

Exec helpers - Moved at https://github.com/projectdiscovery/utils
Go
11
star
62

networkpolicy

Network Policy Helper
Go
10
star
63

resolvercache-go

A DNS response caching library in go
Go
10
star
64

gozero

gozero: the wannabe zero dependency [language-here] runtime for Go developers - Experimental
Go
9
star
65

iputil

ip helpers - Moved at https://github.com/projectdiscovery/utils
Go
8
star
66

dnsx-action

Fast and multi-purpose DNS toolkit allow to run multiple DNS queries.
8
star
67

expirablelru

A TTL expiring LRU cache in go
Go
7
star
68

sslcert

Reworked version of https://golang.org/src/crypto/tls/generate_cert.go
Go
7
star
69

tailwindcss

Design system config file
JavaScript
7
star
70

goconfig

Helper library to save/restore internal values across multiple runs
Go
7
star
71

httpx-action

HTTP Web Server probing
7
star
72

cryptoutil

Library containing various crypto helpers
Go
7
star
73

stringsutil

Strings helper - Moved at https://github.com/projectdiscovery/utils
Go
6
star
74

nuclei-updatecheck-api

Nuclei UpdateChecking API caching github releases for update check
Go
5
star
75

filekv

File based kv store
Go
5
star
76

sarif

Sarif exporter
Go
5
star
77

sliceutil

sliceutils helpers - Moved at https://github.com/projectdiscovery/utils
Go
5
star
78

cloudlist-action

Cloudlist is a tool for listing Assets from multiple Cloud Providers.
5
star
79

mapsutil

Go maps helper functions - Moved at https://github.com/projectdiscovery/utils
Go
4
star
80

gostruct

Python like library to Interpret bytes as packed binary data
Go
4
star
81

folderutil

Package containing various folder helpers
Go
3
star
82

httputil

Http helper library
Go
3
star
83

templates-stats

A utility for extracting various meta data from nuclei-templates.
Go
3
star
84

reflectutil

Library containing reflection helpers
Go
2
star
85

urlutil

Helper library handling edge cases URLs - Moved at https://github.com/projectdiscovery/utils
Go
2
star
86

.github

Community health files for the @projectdiscovery organization
2
star
87

docs

Centralized docs of ProjectDiscovery
MDX
2
star
88

eslint-config

ESLint Configurations
JavaScript
1
star