dotpcap / sharppcap

Official repository - Fully managed, cross platform (Windows, Mac, Linux) .NET library for capturing packets
1.34k stars 268 forks source link

Capture packet from another IP within the same network #362

Closed a6datta closed 2 years ago

a6datta commented 2 years ago

I was able to do the following with pcap.net. I have not found a way to do the same with sharppcap. So I actually have two questions. How can I get the SIP header with sharppcap and can I monitor another IP within the same network.

I am trying to get the details when a VOIP phone rings. The hardware phone is connected to the same network.

I can get the device details as per the example (how can I get a list of devices in another IP) IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;

and get the SIP header

private static void PacketHandler(Packet packet)
        {
            IpV4Datagram ip = packet.Ethernet.IpV4;
            UdpDatagram udp = ip.Udp;9
            Datagram datagram = null;

            if (ip.Protocol == IpV4Protocol.Udp)
            {
                datagram = udp.Payload;

                if (null != datagram)
                {
                    var decoded = datagram.Decode(System.Text.Encoding.UTF8);
                    //i can get the SIP header here
                }
            }
        }
kayoub5 commented 2 years ago

I can get the device details as per the example (how can I get a list of devices in another IP)

I assume you mean RPCAP Use PcapInterface.GetAllPcapInterfaces(IPEndPoint, RemoteAuthentication)

https://github.com/dotpcap/sharppcap/blob/4321129727c79ccb7d2417c03adf5fe2647bf31d/SharpPcap/LibPcap/PcapInterface.cs#L187-L190

See https://github.com/dotpcap/packetnet for how to decode packets.