using System.Collections.Generic;
public static void Main()
string[] msipSpace = new string[] {
var APPFInventory = new string[] {
var MSIPCidrBlocks = msipSpace.SelectMany(BreakCidr);
HashSet<string> ipHashMSIP = new HashSet<string>();
foreach (var c in MSIPCidrBlocks)
ipHashMSIP.Add(ToIpAddress(c.Value));
var APPFCidrBlocks = APPFInventory.SelectMany(BreakCidr);
HashSet<string> ipHashAPPF = new HashSet<string>();
foreach (var c in APPFCidrBlocks)
ipHashAPPF.Add(ToIpAddress(c.Value));
Console.WriteLine(ipHashMSIP.Count);
Console.WriteLine(ipHashAPPF.Count);
foreach (string ip in ipHashAPPF)
if (!ipHashMSIP.Contains(ip))
IEnumerable<KeyValuePair<string, uint>> BreakCidr(string cidr)
string[] a = cidr.Split((char)'/');
if (!IPAddress.TryParse(a[0], out IPAddress ipAddress))
throw new Exception("Bad IP: " + a[0] + " From Bad CIDR:" + cidr);
byte[] address = ipAddress.GetAddressBytes();
uint final = ((uint)address[0] << 24) | ((uint)address[1] << 16) | ((uint)address[2] << 8) | ((uint)address[3]);
yield return new KeyValuePair<string, uint>(cidr, final);
byte[] address = IPAddress.Parse(a[0]).GetAddressBytes();
int prefix = int.Parse(a[1]);
uint mask = GetMask(prefix);
for (int i = 0; i <= mask; i += 1)
byte[] result = new byte[4];
result[0] = (byte)(address[0] | ((byte)(i >> 24) & (byte)0xFF));
result[1] = (byte)(address[1] | ((byte)(i >> 16) & (byte)0xFF));
result[2] = (byte)(address[2] | ((byte)(i >> 8) & (byte)0xFF));
result[3] = (byte)(address[3] | ((byte)(i) & (byte)0xFF));
uint final = ((uint)result[0] << 24) | ((uint)result[1] << 16) | ((uint)result[2] << 8) | ((uint)result[3]);
yield return new KeyValuePair<string, uint>(cidr, final);
string ToIpAddress(uint x)
byte[] address = new byte[4]
return new IPAddress(address).ToString();
return (1u << (32 - prefix)) - 1;