Skip to content

Commit

Permalink
aggregate on filtered ips (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanaReddy0M authored Sep 2, 2024
1 parent dbb2cff commit 79e341c
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions cmd/mapcidr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,18 @@ func process(wg *sync.WaitGroup, chancidr, outputchan chan string) {
ranger, _ = ipranger.New()

for cidr := range chancidr {

// if it's an ip turn it into a cidr
if ip := net.ParseIP(cidr); ip != nil {
if options.FilterIP != nil && sliceutil.Contains(options.FilterIP, cidr) {
continue
}
switch {
case ip.To4() != nil:
cidr += "/32"
case ip.To16() != nil:
cidr += "/128"
}
}
// Add IPs into ipRangeList which are passed as input. Example - "192.168.0.0-192.168.0.5"
if strings.Contains(cidr, "-") {
var ipRange []net.IP
Expand All @@ -381,15 +392,6 @@ func process(wg *sync.WaitGroup, chancidr, outputchan chan string) {
asnNumberList = append(asnNumberList, cidr)
continue
}
// if it's an ip turn it into a cidr
if ip := net.ParseIP(cidr); ip != nil {
switch {
case ip.To4() != nil:
cidr += "/32"
case ip.To16() != nil:
cidr += "/128"
}
}
// test if we have a cidr
if _, pCidr, err = net.ParseCIDR(cidr); err != nil {
gologger.Fatal().Msgf("%s\n", err)
Expand Down

0 comments on commit 79e341c

Please sign in to comment.