当前位置: 首页>>代码示例>>C#>>正文


C# Random.NextMacAddress方法代码示例

本文整理汇总了C#中System.Random.NextMacAddress方法的典型用法代码示例。如果您正苦于以下问题:C# Random.NextMacAddress方法的具体用法?C# Random.NextMacAddress怎么用?C# Random.NextMacAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Random的用法示例。


在下文中一共展示了Random.NextMacAddress方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MacAddressWithBufferTest

        public void MacAddressWithBufferTest()
        {
            Random random = new Random();
            MacAddress address = random.NextMacAddress();

            byte[] buffer = new byte[MacAddress.SizeOf];

            buffer.Write(0, address, Endianity.Big);
            Assert.AreEqual(address, buffer.ReadMacAddress(0, Endianity.Big));
            Assert.AreNotEqual(address, buffer.ReadMacAddress(0, Endianity.Small));

            int offset = 0;
            buffer.Write(ref offset, address, Endianity.Big);
            Assert.AreEqual(address, buffer.ReadMacAddress(0, Endianity.Big));
            Assert.AreEqual(6, offset);

            offset = 0;
            Assert.AreEqual(address, buffer.ReadMacAddress(ref offset, Endianity.Big));
            Assert.AreEqual(MacAddress.SizeOf, offset);

            buffer.Write(0, address, Endianity.Small);
            Assert.AreEqual(address, buffer.ReadMacAddress(0, Endianity.Small));
            Assert.AreNotEqual(address, buffer.ReadMacAddress(0, Endianity.Big));

            offset = 0;
            buffer.Write(ref offset, address, Endianity.Small);
            Assert.AreEqual(address, buffer.ReadMacAddress(0, Endianity.Small));
            Assert.AreEqual(6, offset);

            offset = 0;
            Assert.AreEqual(address, buffer.ReadMacAddress(ref offset, Endianity.Small));
            Assert.AreEqual(MacAddress.SizeOf, offset);
        }
开发者ID:JackWangCUMT,项目名称:WiFiSpy,代码行数:33,代码来源:MacAddressTests.cs

示例2: RandomArpTest

        public void RandomArpTest()
        {
            Random random = new Random();

            for (int i = 0; i != 1000; ++i)
            {
                MacAddress ethernetSource = random.NextMacAddress();
                EthernetLayer ethernetLayer = new EthernetLayer
                                                  {
                                                      Source = ethernetSource,
                                                  };

                ArpLayer arpLayer = random.NextArpLayer();

                Packet packet = PacketBuilder.Build(DateTime.Now, ethernetLayer, arpLayer);

                Assert.IsTrue(packet.IsValid, "IsValid");

                // Ethernet
                Assert.AreEqual(packet.Length - EthernetDatagram.HeaderLengthValue, packet.Ethernet.PayloadLength, "PayloadLength");

                Assert.AreEqual(ethernetSource, packet.Ethernet.Source, "Ethernet Source");
                Assert.AreEqual(EthernetDatagram.BroadcastAddress, packet.Ethernet.Destination, "Ethernet Destination");
                Assert.AreEqual(EthernetType.Arp, packet.Ethernet.EtherType, "Ethernet EtherType");

                // Arp
                Assert.AreEqual(ArpDatagram.HeaderBaseLength + 2 * arpLayer.SenderHardwareAddress.Count + 2 * arpLayer.SenderProtocolAddress.Count, packet.Ethernet.Arp.Length, "Arp length");
                Assert.AreEqual(ArpHardwareType.Ethernet, packet.Ethernet.Arp.HardwareType, "Arp hardware type");
                Assert.AreEqual(arpLayer, packet.Ethernet.Arp.ExtractLayer(), "ARP Layer");
                Assert.AreNotEqual(arpLayer, random.NextArpLayer(), "ARP Layer");
                Assert.AreEqual(arpLayer.GetHashCode(), packet.Ethernet.Arp.ExtractLayer().GetHashCode(), "ARP Layer");
                ArpLayer differentArpLayer = random.NextArpLayer();
                Assert.AreNotEqual(arpLayer.GetHashCode(), differentArpLayer.GetHashCode(), "ARP Layer");
            }
        }
开发者ID:preyea,项目名称:Pcap.Net,代码行数:35,代码来源:ArpTests.cs

示例3: MacAddressTest

        public void MacAddressTest()
        {
            Random random = new Random();

            for (int i = 0; i != 1000; ++i)
            {
                MacAddress macAddress = random.NextMacAddress();

                Assert.IsNotNull(macAddress.ToString());
                Assert.AreEqual(macAddress, new MacAddress(macAddress.ToString()));
                Assert.AreNotEqual(macAddress, random.NextMacAddress());
                Assert.IsTrue(macAddress == new MacAddress(macAddress.ToString()));
                Assert.AreEqual(macAddress.GetHashCode(), new MacAddress(macAddress.ToString()).GetHashCode());
                Assert.IsTrue(macAddress != random.NextMacAddress());
                Assert.AreNotEqual(macAddress.GetHashCode(), random.NextMacAddress().GetHashCode());
            }
        }
开发者ID:JackWangCUMT,项目名称:WiFiSpy,代码行数:17,代码来源:MacAddressTests.cs

示例4: SetSamplingMethodFirstAfterIntervalTest

        public void SetSamplingMethodFirstAfterIntervalTest()
        {
            Random random = new Random();

            MacAddress sourceMac = random.NextMacAddress();
            MacAddress destinationMac = random.NextMacAddress();

            using (PacketCommunicator communicator = OpenLiveDevice())
            {
                communicator.SetFilter("ether src " + sourceMac + " and ether dst " + destinationMac);
                communicator.SetSamplingMethod(new SamplingMethodFirstAfterInterval(TimeSpan.FromSeconds(1)));
                int numPacketsGot;
                communicator.ReceiveSomePackets(out numPacketsGot, 100, p => { });

                Packet[] packetsToSend = new Packet[11];
                packetsToSend[0] = _random.NextEthernetPacket(60, sourceMac, destinationMac);
                for (int i = 0; i != 10; ++i)
                    packetsToSend[i + 1] = _random.NextEthernetPacket(60 * (i + 2), sourceMac, destinationMac);

                List<Packet> packets = new List<Packet>(6);
                Thread thread = new Thread(() => packets.AddRange(communicator.ReceivePackets(6)));
                thread.Start();

                communicator.SendPacket(packetsToSend[0]);
                Thread.Sleep(TimeSpan.FromSeconds(0.7));
                for (int i = 0; i != 10; ++i)
                {
                    communicator.SendPacket(packetsToSend[i + 1]);
                    Thread.Sleep(TimeSpan.FromSeconds(0.55));
                }

                if (!thread.Join(TimeSpan.FromSeconds(10)))
                    thread.Abort();
                Assert.AreEqual(6, packets.Count, packets.Select(p => (p.Timestamp-packets[0].Timestamp).TotalSeconds + "(" + p.Length + ")").SequenceToString(", "));
                Packet packet;
                for (int i = 0; i != 6; ++i)
                    Assert.AreEqual(60 * (i * 2 + 1), packets[i].Length, i.ToString());
                PacketCommunicatorReceiveResult result = communicator.ReceivePacket(out packet);
                Assert.AreEqual(PacketCommunicatorReceiveResult.Timeout, result);
                Assert.IsNull(packet);
            }
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:42,代码来源:LivePacketDeviceTests.cs


注:本文中的System.Random.NextMacAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。