public void SendLayer3Packet(OSI.Layer3Packet packet, PacketSentHandler callback) { IpV4Layer ipV4Layer = new IpV4Layer { Source = new IpV4Address(packet.SourceIP.AsString), Ttl = packet.Ttl, // The rest of the important parameters will be set for each packet }; Common.IPv4Address ip = null; try { System.Net.IPAddress.Parse(packet.Destination); ip = new Common.IPv4Address(packet.Destination); } catch { ip = Dns.ResolveHost(packet.Destination).IPs[0]; } ipV4Layer.CurrentDestination = new IpV4Address(ip.AsString); OSI.Layer2Packet l2 = new OSI.Layer2Packet(); l2.SourceMac = Configuration.MacAddress; l2.DestinationMac = Arp.ResolveIP(ip); foreach (ILayer layer in packet.NextLayers) { l2.NextLayers.Add(layer); } l2.NextLayers.Insert(0, ipV4Layer); SendLayer2Packet(l2, callback); }
public void SendLayer2Packet(OSI.Layer2Packet packet, PacketSentHandler callback) { EthernetLayer ethernetLayer = new EthernetLayer { Source = new MacAddress(packet.SourceMac.AsString), Destination = new MacAddress(packet.DestinationMac.AsString), EtherType = EthernetType.None, // Will be filled automatically. }; List <ILayer> layers = new List <ILayer>(packet.NextLayers); layers.Insert(0, ethernetLayer); Packet pack = PacketBuilder.Build(DateTime.Now, layers.ToArray()); SendPacket(pack, callback); }
public void SendGratuitousArpRequest() { PcapDotNet.Packets.Arp.ArpLayer arpLayer = new PcapDotNet.Packets.Arp.ArpLayer { ProtocolType = PcapDotNet.Packets.Ethernet.EthernetType.IpV4, Operation = ArpOperation.Request, SenderHardwareAddress = _client.Configuration.MacAddress.AsBytes.AsReadOnly(), SenderProtocolAddress = _client.Configuration.IpAddress.AsBytes.AsReadOnly(), TargetHardwareAddress = Common.MacAddress.Broadcast.AsBytes.AsReadOnly(), TargetProtocolAddress = _client.Configuration.IpAddress.AsBytes.AsReadOnly(), }; OSI.Layer2Packet packet = new OSI.Layer2Packet(); packet.DestinationMac = Common.MacAddress.Broadcast; packet.SourceMac = _client.Configuration.MacAddress; packet.NextLayers.Add(arpLayer); SendPacket(packet); }
private void SendArpReplyPacket(Common.IPv4Address ip) { PcapDotNet.Packets.Arp.ArpLayer arpLayer = new PcapDotNet.Packets.Arp.ArpLayer { ProtocolType = PcapDotNet.Packets.Ethernet.EthernetType.IpV4, Operation = ArpOperation.Reply, SenderHardwareAddress = _client.Configuration.MacAddress.AsBytes.AsReadOnly(), SenderProtocolAddress = _client.Configuration.IpAddress.AsBytes.AsReadOnly(), TargetHardwareAddress = ArpCache[ip.AsString].Mac.AsBytes.AsReadOnly(), TargetProtocolAddress = ip.AsBytes.AsReadOnly(), }; OSI.Layer2Packet packet = new OSI.Layer2Packet(); packet.DestinationMac = ArpCache[ip.AsString].Mac; packet.SourceMac = _client.Configuration.MacAddress; packet.NextLayers.Add(arpLayer); SendPacket(packet); }