mapcidr

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2020 License: MIT Imports: 6 Imported by: 113

README

mapCIDR

License Go Report Card contributions welcome Follow on Twitter Chat on Discord

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

mapCIDR

  • Simple and modular code base making it easy to contribute.
  • CIDR distribution for distributed scanning.
  • Stdin and stdout support for integrating in workflows

Installation:-

From Source
▶ GO111MODULE=auto go get -u github.com/projectdiscovery/mapcidr/cmd/mapcidr
From Github
▶ 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 chaos 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

                   ____________  ___    
  __ _  ___ ____  / ___/  _/ _ \/ _ \
 /  ' \/ _ '/ _ \/ /___/ // // / , _/   
/_/_/_/\_,_/ .__/\___/___/____/_/|_| v0.1
          /_/                                                     	 

		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

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
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

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
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.

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.

Documentation

Overview

Package mapcidr implements methods to allow working with CIDRs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddressCount

func AddressCount(cidr string) (uint64, error)

AddressCount returns the number of IP addresses in a range

func AddressCountIpnet

func AddressCountIpnet(network *net.IPNet) uint64

AddressCountIpnet returns the number of IP addresses in an IPNet structure

func AddressRange

func AddressRange(network *net.IPNet) (net.IP, net.IP, error)

AddressRange returns the first and last addresses in the given CIDR range.

func IPAddresses added in v0.0.2

func IPAddresses(cidr string) ([]string, error)

IPAddresses returns all the IP addresses in a CIDR

func IPAddressesIPnet added in v0.0.2

func IPAddressesIPnet(ipnet *net.IPNet) (ips []string)

IPAddressesIPnet returns all IP addresses in an IPNet.

func IPToInteger added in v0.0.2

func IPToInteger(ip net.IP) (*big.Int, int, error)

IPToInteger converts an IP address to its integer representation. It supports both IPv4 as well as IPv6 addresses.

func IntegerToIP added in v0.0.2

func IntegerToIP(ipInt *big.Int, bits int) net.IP

IntegerToIP converts an Integer IP address to net.IP format.

func SplitByNumber

func SplitByNumber(iprange string, number int) ([]*net.IPNet, error)

SplitByNumber splits the given cidr into subnets with the closest number of hosts per subnet.

func SplitIPNetByNumber added in v0.0.2

func SplitIPNetByNumber(ipnet *net.IPNet, number int) ([]*net.IPNet, error)

SplitIPNetByNumber splits an IPNet into subnets with the closest n umber of hosts per subnet.

func SplitIPNetIntoN added in v0.0.2

func SplitIPNetIntoN(iprange *net.IPNet, n int) ([]*net.IPNet, error)

SplitIPNetIntoN attempts to split a ipnet in the exact number of subnets

func SplitN

func SplitN(iprange string, n int) ([]*net.IPNet, error)

SplitN attempts to split a cidr in the exact number of subnets

Types

This section is empty.

Directories

Path Synopsis
cmd
mapcidr command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL