Search code examples
.netsharppcap

Source and destination IP of ICMP packet


I am capturing packets with Sharp Pcap, I can easily check IP of IPpacket or ARP packet:

Dim ip1 As IpPacket = IpPacket.GetEncapsulated(pack)
Dim arp As ARPPacket = ARPPacket.GetEncapsulated(pack)

    If (Not ip1 Is Nothing) Then
        log1.WriteLine("Received IP packet from {0}", ip1.SourceAddress.ToString)
    End If

    If (Not arp Is Nothing) Then
        log1.WriteLine("Received ARP packet from {0}", arp.SenderProtocolAddress.ToString)
    End If

I wanted to find properties for ICMPPacket, with no luck. How can I check source/destination address of ICMPPacket?


Solution

  • ICMP packet is part of IP packet, thus to get source IP of ICMPPacket, you have to get source address of IP packet then check if it's ICMPPacket