mapcidr icon indicating copy to clipboard operation
mapcidr copied to clipboard

[Feature] deaggregate function

Open IgorSeryogin opened this issue 2 years ago • 2 comments

Hi

It would be nice to have Deaggregate function to convert first and last IP of range to slice of prefixes. For example RIPE returns following json output:

"166.8.0.0/16",
"166.9.0.0-166.10.255.255",
"166.11.0.0/16",

So I need to convert IP range "166.9.0.0-166.10.255.255" to list of prefixes [166.9.0.0/16, 166.10.0.0/16] It could be something like this:

func Deaggregate(first, last *net.IP) []*net.IPNet

thx

IgorSeryogin avatar Jul 28 '22 18:07 IgorSeryogin

@IgorSeryogin Thanks for opening this issue. The functionality requested is to convert dash separated IP intervals xx.xx.xx.xx-yy.yy.yy.yy to aggregated cidr? I'm asking to ensure I understand correctly, as this looks like an aggregation operation

Mzack9999 avatar Aug 03 '22 08:08 Mzack9999

Dash separated IPs or just first and last IP, that`s no matter. And the result could be as single CIDR or list of CIDRs For instance:

192.168.0.0-192.168.0.255 ==> 
[192.168.0.0/24]

192.168.0.1-192.168.0.255 ==> 
[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]

Here is an example of online tools which do the same:

  • https://tehnoblog.org/ip-tools/ip-address-aggregator/
  • https://dig.ua/ipcalc.html

IgorSeryogin avatar Aug 03 '22 16:08 IgorSeryogin

@IgorSeryogin thank you for the details, I've created another issue based on your input https://github.com/projectdiscovery/mapcidr/issues/98 and standard IP range-based input should cover what you described as your use case.

ehsandeep avatar Aug 29 '22 15:08 ehsandeep

@IgorSeryogin, this is now supported with the latest release. Thanks again for the feature request - https://github.com/projectdiscovery/mapcidr/releases/tag/v1.0.2

ehsandeep avatar Sep 12 '22 22:09 ehsandeep