dotpcap / sharppcap

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

get the packet info not from event #456

Closed mayyola closed 1 year ago

mayyola commented 1 year ago

Hello,Sir

void Device_OnPacketArrival(object s, PacketCapture e) { Console.WriteLine(e.Packet); static string parameter }

using var device = LibPcapLiveDeviceList.Instance[0]; device.Open(); device.OnPacketArrival += Device_OnPacketArrival; device.StartCapture(); Messagebox.show(static string parameter) it's not working

is it possible get the parse the package from outside not Device_OnPacketArrival event ? cause the event is void ,can't not return even i add the static string parameter to save packet in the Device_OnPacketArrival when i call the static string parameter from other method , it's not working could you teach me how to do thank you

kayoub5 commented 1 year ago

use GetNextPacket instead of startcapture/event handler

mayyola commented 1 year ago

Hello,Sir I have another question I use the object send instruction NetworkStream ns = tmpTcpClient.GetStream(); and use the GetNextPacket to receive the particular package,i specific ip address,such as devices.Filter = "src host 192.168.20.15";

but it will be generated the exception,"System.IndexOutOfRangeException: Index was outside the bounds of the array."

if use devices.Filter ="ip and tcp" is successful, but I just want send the instruction and get response from particular machine

immediately. thank you for any help

devices = LibPcapLiveDeviceList.Instance[3]; devices.Open(); devices.Filter = "src host 192.168.20.15"; var rawCapture = devices.GetNextPacket(out var packet); var packet_final = Packet.ParsePacket(packet.Device.LinkType, packet.Data.ToArray()); ethernetPacket = (EthernetPacket)packet_final; Console.WriteLine(ethernetPacket);

kayoub5 commented 1 year ago

if you have a different problem, close this issue and open a new one.

what is the question? you are just describing vaguely a problem you have without context, full code or a stack trace.