Example #1
0
        public void TestToString()
        {
            IPAddress a = IPAddress.Parse("127.2.3.0");
            Subnet mask = new Subnet(a, 24);

            Assert.AreEqual("127.2.3.0/24", mask.ToString());
        }
Example #2
0
        public void TestSingleIp()
        {
            IPAddress a = IPAddress.Parse("127.2.3.4");
            IPAddress b = IPAddress.Parse("127.2.3.3");
            IPAddress c = IPAddress.Parse("127.2.3.255");
            IPAddress d = IPAddress.Parse("127.2.3.0");

            Subnet mask = new Subnet(a, 32);

            Assert.IsTrue(mask.InSubnet(a));
            Assert.IsFalse(mask.InSubnet(b));
            Assert.IsFalse(mask.InSubnet(c));
            Assert.IsFalse(mask.InSubnet(d));
        }
Example #3
0
        public void Test16()
        {
            IPAddress a = IPAddress.Parse("127.2.0.0");
            IPAddress b = IPAddress.Parse("127.2.3.4");
            IPAddress c = IPAddress.Parse("127.2.129.255");
            IPAddress d = IPAddress.Parse("127.3.4.4");

            Subnet mask = new Subnet(a, 16);

            Assert.IsTrue(mask.InSubnet(a));
            Assert.IsTrue(mask.InSubnet(b));
            Assert.IsTrue(mask.InSubnet(c));
            Assert.IsFalse(mask.InSubnet(d));
        }
Example #4
0
        public void TestEquals()
        {
            Subnet a = new Subnet(IPAddress.Parse("127.2.3.4"), 32);
            Subnet b = new Subnet(IPAddress.Parse("127.2.3.4"), 32);
            Subnet c = new Subnet(IPAddress.Parse("127.2.3.5"), 32);
            Subnet d = new Subnet(IPAddress.Parse("127.2.3.5"), 24);

            Assert.IsTrue(a.Equals(b));
            Assert.IsFalse(a.Equals(c));
            Assert.IsFalse(a.Equals(d));
            Assert.IsFalse(a.Equals(null));
        }
Example #5
0
        public void TestToStringLiteral()
        {
            IPAddress a = IPAddress.Loopback;
            Subnet mask = new Subnet(a, 32);

            Assert.AreEqual("127.0.0.1/32", mask.ToString());
        }
Example #6
0
 /// <summary>
 /// Unblocks the specified subnet.
 /// </summary>
 private void Unblock(Subnet subnet)
 {
     if (subnet == null)
         throw new ArgumentNullException("subnet");
     lock (((IList)_blacklist).SyncRoot)
     {
         _blacklist.Remove(subnet);
     }
 }
Example #7
0
 /// <summary>
 /// Blocks the specified subnet.
 /// </summary>
 public void Block(Subnet subnet)
 {
     if (subnet == null)
         throw new ArgumentNullException("subnet");
     lock (((IList)_blacklist).SyncRoot)
     {
         _blacklist.Add(subnet);
     }
 }
Example #8
0
 /// <summary>
 /// Sets the subnets to be blacklisted.
 /// </summary>
 public void SetSubnetBlacklist(Subnet[] subnets)
 {
     if (subnets == null)
         throw new ArgumentNullException("subnets");
     lock (((IList)_blacklist).SyncRoot)
     {
         _blacklist.Clear();
         foreach (Subnet subnet in subnets)
         {
             Block(subnet);
         }
     }
 }