Ejemplo n.º 1
0
        public static void Netmask_CIDR_OutOfRange(int cidr)
        {
            // Arrange

            // Act
            Assert.Throws <ArgumentOutOfRangeException>(() => IpNumberHelper.Netmask(cidr));

            // Assert
        }
Ejemplo n.º 2
0
        public static void Netmask(string expected, int cidr)
        {
            // Arrange

            // Act
            var result = IpNumberHelper.Netmask(cidr);

            // Assert
            Assert.Equal(expected, IpNumberHelper.ToIpString(result));
        }
Ejemplo n.º 3
0
        public static void Broadcast(string expected, string ip, int cidr)
        {
            // Arrange
            var mask  = IpNumberHelper.Netmask(cidr);
            var ipnum = IpNumberHelper.Network(IpNumberHelper.ToIpNumber(ip), mask);

            // Act
            var result = IpNumberHelper.Broadcast(ipnum, mask);

            // Assert
            Assert.Equal(expected, IpNumberHelper.ToIpString(result));
        }
Ejemplo n.º 4
0
        public static void Contains(bool expected, string net, int cidr, string ip)
        {
            // Arrange
            var network = IpNumberHelper.ToIpNumber(net);
            var mask    = IpNumberHelper.Netmask(cidr);
            var ipnum   = IpNumberHelper.ToIpNumber(ip);

            // Act
            var result = IpNumberHelper.Contains(network, mask, ipnum);

            // Assert
            Assert.Equal(expected, result);
        }
Ejemplo n.º 5
0
        private static IpNetwork[] Parse(string[] networks)
        {
            var result = new List <IpNetwork>();

            foreach (var net in networks)
            {
                var parts = net.Split('/');
                if (parts.Length != 2)
                {
                    throw new InvalidOperationException("Invalid network");
                }

                result.Add(new IpNetwork()
                {
                    Network = IpNumberHelper.ToIpNumber(parts[0]),
                    Mask    = IpNumberHelper.Netmask(Int32.Parse(parts[1], NumberStyles.Integer, CultureInfo.InvariantCulture))
                });
            }

            return(result.ToArray());
        }