He estado siguiendo la guía en http://www.codeproject.com/KB/IP/sharppcap.aspx para implementar un simple sniffer de paquetes para automatizar las autenticaciones, he logrado acceder a la sección de Filtrado y he tenido que hacer algunos ajustes al código del tutorial hasta ahora para que funcione, pero ahora estoy perplejo.No se puede convertir de SharpPcap.RawCapture a PacketDotNet.Packet
El error que estoy recibiendo es;
El partido mejor método sobrecargado para 'PacketDotNet.TcpPacket.GetEncapsulated (PacketDotNet.Packet)' tiene algunos argumentos no válidos
Argumento 1: no se puede convertir de 'SharpPcap.RawCapture' a 'PacketDotNet.Packet'
Pero todavía no he hecho ninguna referencia a mi propio PacketDotNet (todo hasta ahora ha sido SharpPcap).
Todo el código que tengo hasta ahora se incluye, el problema está en la función device_OnPacketArrival().
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PacketDotNet;
using SharpPcap;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string ver = SharpPcap.Version.VersionString;
Console.WriteLine("SharpPcap {0}, Example1.IfList.cs", ver);
// Retrieve the device list
CaptureDeviceList devices = CaptureDeviceList.Instance;
// If no devices were found print an error
if (devices.Count < 1)
{
Console.WriteLine("No devices were found on this machine");
return;
}
// Extract a device from the list
ICaptureDevice device = devices[0];
// Register our handler function to the
// 'packet arrival' event
device.OnPacketArrival +=
new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival);
// Open the device for capturing
int readTimeoutMilliseconds = 1000;
device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
// tcpdump filter to capture only TCP/IP packets
string filter = "ip and tcp";
device.Filter = filter;
Console.WriteLine();
Console.WriteLine("-- The following tcpdump filter will be applied: \"{0}\"",
filter);
Console.WriteLine("-- Listening on {0}, hit 'Enter' to stop...",
device.Description);
// Start capturing packets indefinitely
device.Capture();
// Close the pcap device
// (Note: this line will never be called since
// we're capturing indefinitely
device.Close();
}
private static void device_OnPacketArrival(object sender, CaptureEventArgs e)
{
var tcp = TcpPacket.GetEncapsulated(e.Packet);
}
}
}
Parece que no tengo la clase .Packet.Parse, la más cercana a Parse es TcpPacket.ParsePacket(), pero no estoy seguro de dónde sacaste LinkLayer (¿cuál es la referencia de rawPacket en esta situación? , yo esperaría que sea e.Packet pero no estoy 100% seguro) – Clorith
actualizado mi respuesta con el nombre del método correcto. –
haciendo referencia al ejemplo 12 ahora, y solo tienen 1 argumento, pero sigo recibiendo un error; "Sin sobrecarga para el método 'ParsePacket' toma 1 argumento", todo esto es muy confuso en este momento. – Clorith