Sending my own ARP packet using SharpPcap and Packet.Net

梦想的初衷 提交于 2019-12-22 05:33:37

问题


I am trying unsuccessfully so far to send an ARP packet I have created with Packet.Net using SharpPcap. The problem is even though I send the packet using device.SendPacket it doesn't actually get sent, and I have no idea why.

This is my code:

ARPPacket arpPacket = new ARPPacket(ARPOperation.Request, PhysicalAddress.Parse("000000000000"), targetIpAddress, device.Interface.MacAddress, myIpAddress);
EthernetPacket ethPacket = new EthernetPacket(device.Interface.MacAddress, PhysicalAddress.Parse("FFFFFFFFFFFF"), EthernetPacketType.Arp);
ethPacket.PayloadPacket = arpPacket;
device.Open();
device.SendPacket(ethPacket);
device.Close();

By the way, it is important that I send my own ARP packets and not just use the SharpPcap ARP class.


回答1:


public static void ARP(IPAddress ipAddress , LivePcapDevice device)
{
if (ipAddress == null )
throw new Exception("ARP IP address Cannot be null");
var ethernetPacket = new PacketDotNet.EthernetPacket(device.Addresses[1].Addr.hardwareAddress, PhysicalAddress.Parse("FF-FF-FF-FF-FF-FF"), PacketDotNet.EthernetPacketType.Arp);

var arpPacket = new PacketDotNet.ARPPacket(PacketDotNet.ARPOperation.Request, PhysicalAddress.Parse("00-00-00-00-00-00"), ipAddress , device.Addresses[1].Addr.hardwareAddress, device.Addresses[0].Addr.ipAddress );
ethernetPacket.PayloadPacket = arpPacket;

device.SendPacket(ethernetPacket);
}

Try this function, from: http://stolenpackets.net/?p=29




回答2:


looking at this code there is no ethernetpacket involved

ARPPacket arpPacket = new ARPPacket(ARPOperation.Request, PhysicalAddress.Parse("000000000000"), targetIpAddress, device.Interface.MacAddress, myIpAddress);
arpPacket.ARPTargetProtoAddress = destIP;
arpPacket.DestinationHwAddress = PhysicalAddress.Parse("FF-FF-FF-FF-FF-FF");
device.Open();
device.SendPacket(arpPacket);
device.Close();


来源:https://stackoverflow.com/questions/14114971/sending-my-own-arp-packet-using-sharppcap-and-packet-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!