static List <IPNetwork> RecursiveAdd(IPNetwork target, IPNetwork subtract, List <IPNetwork> newNetwork) { if (subtract.Contains(target) || target.Cidr >= 31) { return(newNetwork); } var splitted = Split(target); var firstOverLap = subtract.Overlap(splitted[0]); var secondOverlap = subtract.Overlap(splitted[1]); if (firstOverLap && secondOverlap) { RecursiveAdd(splitted[0], subtract, newNetwork); RecursiveAdd(splitted[1], subtract, newNetwork); } else if (firstOverLap) { newNetwork.Add(splitted[1]); RecursiveAdd(splitted[0], subtract, newNetwork); } else if (secondOverlap) { newNetwork.Add(splitted[0]); RecursiveAdd(splitted[1], subtract, newNetwork); } return(newNetwork); }
protected override void EndProcessing() { Subnets.Sort(); Subnet last = null; foreach (Subnet s in Subnets) { if (last == null) { WriteObject(s.Input); last = s; } else { if (last.Network == s.Network) { WriteVerbose($"{last.Input} equals {s.Input}. Removing duplicate from list."); } else if (IPNetwork.Overlap(last.Network, s.Network)) { WriteVerbose($"{last.Input} overlaps {s.Input}. Removing {s.Input} from list."); } else { WriteObject(s.Input); last = s; } } } }
private static void OverlapNetwork(ProgramContext ac) { foreach (IPNetwork ipnetwork in ac.Networks) { bool overlap = IPNetwork.Overlap(ac.OverlapNetwork, ipnetwork); Console.WriteLine("{0} overlaps {1} : {2}", ac.OverlapNetwork, ipnetwork, overlap); } }