mapcidr
mapcidr copied to clipboard
[Feature] deaggregate function
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 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
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 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.
@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