Пример #1
0
        public void Invert()
        {
            var addr     = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("0.0.15.255").GetAddressBytes());
            var expected = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("255.255.240.0").GetAddressBytes());

            Assert.Equal(expected, addr.Invert());
        }
Пример #2
0
        public void Increment()
        {
            var addr     = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("192.168.1.1"));
            var expected = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("192.168.2.3"));

            Assert.Equal(expected, addr.Increment(258));
        }
Пример #3
0
        public void BuildMaskFromBits()
        {
            var addr     = SnmpSharpNet.Types.IpAddress.BuildMaskFromBits(19);
            var expected = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("255.255.224.0").GetAddressBytes());

            Assert.Equal(addr, expected);
        }
Пример #4
0
        public void GetBroadcastAddress()
        {
            var addr     = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("10.100.17.1").GetAddressBytes());
            var mask     = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("255.255.240.0").GetAddressBytes());
            var expected = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("10.100.31.255").GetAddressBytes());

            Assert.Equal(expected, addr.GetBroadcastAddress(mask));
        }
Пример #5
0
        public void IsValidMask()
        {
            var addr = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("255.255.224.0").GetAddressBytes());

            Assert.True(addr.IsValidMask());

            addr = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("255.255.225.0").GetAddressBytes());
            Assert.False(addr.IsValidMask());
        }
Пример #6
0
        public void GetMaskBits()
        {
            var addr = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("255.255.224.0").GetAddressBytes());

            Assert.Equal(19, addr.GetMaskBits());

            addr = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("255.255.225.0").GetAddressBytes());
            Assert.Equal(0, addr.GetMaskBits());
        }
Пример #7
0
        public void GetNetworkMask()
        {
            var addr     = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("10.100.1.1").GetAddressBytes());
            var expected = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("255.0.0.0").GetAddressBytes());

            Assert.Equal(expected, addr.NetworkMask());

            addr     = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("172.24.24.24").GetAddressBytes());
            expected = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("255.255.0.0").GetAddressBytes());
            Assert.Equal(expected, addr.NetworkMask());

            addr     = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("192.168.255.255").GetAddressBytes());
            expected = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("255.255.255.0").GetAddressBytes());
            Assert.Equal(expected, addr.NetworkMask());

            addr = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("224.0.0.5").GetAddressBytes());
            Assert.Null(addr.NetworkMask());
        }
Пример #8
0
        public void GetClass()
        {
            var addr = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("10.100.1.1").GetAddressBytes());

            Assert.Equal(SnmpSharpNet.Types.IpAddress.Class.A, addr.GetClass());

            addr = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("172.24.24.24").GetAddressBytes());
            Assert.Equal(SnmpSharpNet.Types.IpAddress.Class.B, addr.GetClass());

            addr = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("192.168.255.255").GetAddressBytes());
            Assert.Equal(SnmpSharpNet.Types.IpAddress.Class.C, addr.GetClass());

            addr = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("224.0.0.5").GetAddressBytes());
            Assert.Equal(SnmpSharpNet.Types.IpAddress.Class.D, addr.GetClass());

            addr = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("245.244.243.242").GetAddressBytes());
            Assert.Equal(SnmpSharpNet.Types.IpAddress.Class.E, addr.GetClass());

            addr = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("255.255.255.255").GetAddressBytes());
            Assert.Equal(SnmpSharpNet.Types.IpAddress.Class.Invalid, addr.GetClass());
        }
Пример #9
0
        public void ToUInt32Host()
        {
            var addr = new SnmpSharpNet.Types.IpAddress(System.Net.IPAddress.Parse("10.100.1.1").GetAddressBytes());

            Assert.Equal(0x0A640101U, addr.ToUInt32Host());
        }