本文整理汇总了C#中System.Random.NextIpV4Address方法的典型用法代码示例。如果您正苦于以下问题:C# Random.NextIpV4Address方法的具体用法?C# Random.NextIpV4Address怎么用?C# Random.NextIpV4Address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Random
的用法示例。
在下文中一共展示了Random.NextIpV4Address方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IpV4AddressRandomTest
public void IpV4AddressRandomTest()
{
Assert.AreEqual(IpV4Address.AllHostsGroupAddress, new IpV4Address("224.0.0.1"));
Random random = new Random();
for (int i = 0; i != 1000; ++i)
{
IpV4Address address = random.NextIpV4Address();
Assert.AreEqual(address, new IpV4Address(address.ToString()));
Assert.IsTrue(address == new IpV4Address(address.ToString()));
Assert.IsFalse(address != new IpV4Address(address.ToString()));
Assert.AreEqual(address.GetHashCode(), new IpV4Address(address.ToString()).GetHashCode());
Assert.AreEqual(address, new IpV4Address(address.ToValue()));
Assert.AreNotEqual(address, random.NextIpV4Address());
Assert.IsFalse(address == random.NextIpV4Address());
Assert.IsTrue(address != random.NextIpV4Address());
Assert.AreNotEqual(address.GetHashCode(), random.NextIpV4Address().GetHashCode());
Assert.AreNotEqual(2, address);
Assert.IsFalse(address.Equals(null));
}
}
示例2: InvalidGreTest
public void InvalidGreTest()
{
EthernetLayer ethernetLayer = new EthernetLayer
{
Source = new MacAddress("00:01:02:03:04:05"),
Destination = new MacAddress("A0:A1:A2:A3:A4:A5")
};
Random random = new Random();
for (int i = 0; i != 100; ++i)
{
IpV4Layer ipV4Layer = random.NextIpV4Layer(IpV4Protocol.Gre);
ipV4Layer.HeaderChecksum = null;
GreLayer greLayer = random.NextGreLayer();
greLayer.Checksum = null;
greLayer.Routing = new List<GreSourceRouteEntry>
{
new GreSourceRouteEntryAs(new List<ushort> {123}.AsReadOnly(), 0),
new GreSourceRouteEntryIp(new List<IpV4Address> {random.NextIpV4Address()}.AsReadOnly(),
0)
}.AsReadOnly();
PacketBuilder packetBuilder = new PacketBuilder(ethernetLayer, ipV4Layer, greLayer);
Packet packet = packetBuilder.Build(DateTime.Now);
Assert.IsTrue(packet.IsValid ||
new[] {EthernetType.IpV4, EthernetType.Arp, EthernetType.VLanTaggedFrame}.Contains(greLayer.ProtocolType),
"IsValid. ProtoclType=" + greLayer.ProtocolType);
GreDatagram gre = packet.Ethernet.IpV4.Gre;
// Remove a byte from routing
Datagram newIpPayload = new Datagram(gre.Take(gre.Length - 1).ToArray());
packetBuilder = new PacketBuilder(ethernetLayer, ipV4Layer, new PayloadLayer {Data = newIpPayload});
packet = packetBuilder.Build(DateTime.Now);
Assert.IsNull(packet.Ethernet.IpV4.Gre.Payload);
Assert.IsFalse(packet.IsValid);
// SreLength is too big
byte[] buffer = gre.ToArray();
buffer[buffer.Length - 1] = 200;
newIpPayload = new Datagram(buffer);
packetBuilder = new PacketBuilder(ethernetLayer, ipV4Layer, new PayloadLayer {Data = newIpPayload});
packet = packetBuilder.Build(DateTime.Now);
Assert.IsFalse(packet.IsValid);
// PayloadOffset is too big
buffer = gre.ToArray();
buffer[gre.Length - 10] = 100;
newIpPayload = new Datagram(buffer);
packetBuilder = new PacketBuilder(ethernetLayer, ipV4Layer, new PayloadLayer {Data = newIpPayload});
packet = packetBuilder.Build(DateTime.Now);
Assert.IsFalse(packet.IsValid);
// PayloadOffset isn't aligned to ip
buffer = gre.ToArray();
buffer[gre.Length - 10] = 3;
newIpPayload = new Datagram(buffer);
packetBuilder = new PacketBuilder(ethernetLayer, ipV4Layer, new PayloadLayer {Data = newIpPayload});
packet = packetBuilder.Build(DateTime.Now);
Assert.IsFalse(packet.IsValid);
// PayloadOffset isn't aligned to as
buffer = gre.ToArray();
buffer[gre.Length - 16] = 1;
newIpPayload = new Datagram(buffer);
packetBuilder = new PacketBuilder(ethernetLayer, ipV4Layer, new PayloadLayer {Data = newIpPayload});
packet = packetBuilder.Build(DateTime.Now);
Assert.IsFalse(packet.IsValid);
}
}
示例3: IpV4AddressWithBufferTest
public void IpV4AddressWithBufferTest()
{
Random random = new Random();
for (int i = 0; i != 1000; ++i)
{
IpV4Address address = random.NextIpV4Address();
byte[] buffer = new byte[IpV4Address.SizeOf];
buffer.Write(0, address, Endianity.Big);
Assert.AreEqual(address, buffer.ReadIpV4Address(0, Endianity.Big));
Assert.AreNotEqual(address, buffer.ReadIpV4Address(0, Endianity.Small));
buffer.Write(0, address, Endianity.Small);
Assert.AreEqual(address, buffer.ReadIpV4Address(0, Endianity.Small));
Assert.AreNotEqual(address, buffer.ReadIpV4Address(0, Endianity.Big));
}
}
示例4: IcmpRouterAdvertisementEntryTest
public void IcmpRouterAdvertisementEntryTest()
{
Random random = new Random();
IcmpRouterAdvertisementEntry entry1 = new IcmpRouterAdvertisementEntry(random.NextIpV4Address(), random.Next());
IcmpRouterAdvertisementEntry entry2 = new IcmpRouterAdvertisementEntry(random.NextIpV4Address(), random.Next());
Assert.AreEqual(entry1, entry1);
Assert.AreEqual(entry1.GetHashCode(), entry1.GetHashCode());
Assert.AreNotEqual(entry1, entry2);
Assert.AreNotEqual(entry1.GetHashCode(), entry2.GetHashCode());
}