Пример #1
0
        public void AppendSrcPortTest()
        {
            var filter = new PcapFilterBuilder()
                         .AppendPortSrc(80)
                         .ToString();

            Assert.Equal("src port 80", filter);
        }
Пример #2
0
        public void AppendIpSrcTest()
        {
            var filter = new PcapFilterBuilder()
                         .AppendIpSrc(new IPAddress(new byte[] { 127, 0, 0, 1 }))
                         .ToString();

            Assert.Equal("src host 127.0.0.1", filter);
        }
Пример #3
0
        public void AppendEthAddrTest()
        {
            var filter = new PcapFilterBuilder()
                         .AppendEthAddr(new PhysicalAddress(new byte[] { 0, 1, 2, 3, 4, byte.MaxValue }))
                         .ToString();

            Assert.Equal("ether host 00:01:02:03:04:FF", filter);
        }
Пример #4
0
        public void AppendIpSrcTest_TwoIpAddresses()
        {
            var filter = new PcapFilterBuilder()
                         .AppendIpSrc(
                new IPAddress(new byte[] { 127, 0, 0, 1 }),
                new IPAddress(new byte[] { 127, 0, 0, 2 })
                )
                         .ToString();

            Assert.Equal("( src host 127.0.0.1 || src host 127.0.0.2 )", filter);
        }
Пример #5
0
        public void AppendIpSrcTest_OneIpV4AndOneIpV6()
        {
            var ipv4  = "127.0.0.1";
            var ipv6A = "fe80::d5bd:f894:fff8:93ce%5";
            var ipv6B = "fe80::d5bd:f894:fff8:93ce%15";

            var filter = new PcapFilterBuilder()
                         .AppendIpSrc(
                IPAddress.Parse(ipv4),
                IPAddress.Parse(ipv6A),
                IPAddress.Parse(ipv6B)
                )
                         .ToString();

            Assert.Equal(
                $"( src host {ipv4} || src host {TrimIpV6(ipv6A)} || src host {TrimIpV6(ipv6B)} )",
                filter
                );
        }
Пример #6
0
        public async Task DataLengthTest_FilterBuilder_ExpectPacketReceived()
        {
            var pingIp        = IPAddress.Parse(PING_IP);
            var filterBuilder = new PcapFilterBuilder()
                                .AppendIpDst(pingIp);

            var receivedBytes = await new TaskFactory().StartNew(
                () => {
                var monitor = new NetMonitor(filterBuilder);
                monitor.Start();

                Ping(PING_IP);
                Thread.Sleep(1000);

                monitor.Stop();
                return(monitor.ReceivedBytes);
            }
                );

            Assert.True(receivedBytes > 0);
        }
Пример #7
0
 public NetMonitor(PcapFilterBuilder filterBuilder)
     : this(filterBuilder.ToString())
 {
 }