public static int SubnetMaskToInt(IPAddress ip)
 {
     return SubnetMaskToInt((uint)ip.ToInt());
 }
        public IPGroup GetIPGroup(IPAddress ip)
        {
            var ipGroup = db.IPGroups.AsEnumerable().SingleOrDefault(x =>
                (new IPAddress(x.SubnetMask.Address).ToInt() & ip.ToInt()) ==
                (new IPAddress(x.IP.Address).ToInt() & new IPAddress(x.SubnetMask.Address).ToInt()));

            return ipGroup;
        }