Пример #1
0
        private void SendIcmpReplyPacket(Packet request)
        {
            var icmp = request.Ethernet.IpV4.Icmp as IcmpEchoDatagram;

            OSI.Layer3Packet packet = new OSI.Layer3Packet();
            packet.Destination = request.Ethernet.IpV4.Source.ToString();
            packet.SourceIP    = _client.Configuration.IpAddress;
            packet.Ttl         = (byte)(request.Ethernet.IpV4.Ttl / 2);
            var data = icmp.ToArray();

            data = data.Subsegment(8, data.Length - 8).ToArray();

            PcapDotNet.Packets.Icmp.IcmpEchoReplyLayer icmpLayer =
                new PcapDotNet.Packets.Icmp.IcmpEchoReplyLayer
            {
                Checksum       = null,
                Identifier     = icmp.Identifier,
                SequenceNumber = (ushort)(icmp.SequenceNumber),
            };
            PcapDotNet.Packets.PayloadLayer extra = new PcapDotNet.Packets.PayloadLayer()
            {
                Data = new PcapDotNet.Packets.Datagram(data)
            };

            packet.NextLayers.Add(icmpLayer);
            packet.NextLayers.Add(extra);

            SendPacket(packet);
        }
        public override ILayer ExtractLayer()
        {
            IcmpEchoReplyLayer icmpEchoReplyLayer = new IcmpEchoReplyLayer();

            icmpEchoReplyLayer.Checksum       = new ushort?(this.Checksum);
            icmpEchoReplyLayer.Identifier     = this.Identifier;
            icmpEchoReplyLayer.SequenceNumber = this.SequenceNumber;
            return((ILayer)icmpEchoReplyLayer);
        }
Пример #3
0
        private static Packet BuildIcmpPacket(MacAddress SourceMac, MacAddress DestinationMac, IpV4Address SourceIp, IpV4Address CurrentDestination, string packetType)
        {
            EthernetLayer ethernetLayer =
                new EthernetLayer
                {
                    Source = SourceMac,
                    Destination = DestinationMac,
                    EtherType = EthernetType.None, // Will be filled automatically.
                };

            IpV4Layer ipV4Layer =
                new IpV4Layer
                {
                    //Source = new IpV4Address("1.2.3.4"),
                    //CurrentDestination = new IpV4Address("11.22.33.44"),
                    Source = SourceIp,
                    CurrentDestination = CurrentDestination,
                    Fragmentation = IpV4Fragmentation.None,
                    HeaderChecksum = null, // Will be filled automatically.
                    Identification = 123,
                    Options = IpV4Options.None,
                    Protocol = null, // Will be filled automatically.
                    Ttl = 100,
                    TypeOfService = 0,
                };

            IcmpEchoLayer icmpLayer = null;
            IcmpEchoReplyLayer icmpRLayer = null;

            PacketBuilder builder = null;

            if (packetType.Equals("REQUEST"))
            {
                Console.WriteLine("Request");
                icmpLayer =
                    new IcmpEchoLayer
                    {
                        Checksum = null, // Will be filled automatically.
                        Identifier = 456,
                        SequenceNumber = 800,
                    };
                builder = new PacketBuilder(ethernetLayer, ipV4Layer, icmpLayer);
            }
            else
            {
                Console.WriteLine("Reply");
                icmpRLayer =
                    new IcmpEchoReplyLayer
                    {
                        Checksum = null, // Will be filled automatically.
                        Identifier = 456,
                        SequenceNumber = 800,
                    };
                builder = new PacketBuilder(ethernetLayer, ipV4Layer, icmpRLayer);
            }

            return builder.Build(DateTime.Now);
        }