6

到目前为止,我试图发送一个使用 SharpPcap 使用 Packet.Net 创建的 ARP 数据包,但没有成功。问题是即使我使用device.SendPacket它发送数据包实际上并没有发送,我也不知道为什么。

这是我的代码:

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();

顺便说一句,重要的是我发送自己的 ARP 数据包,而不仅仅是使用 SharpPcap ARP 类。

4

2 回答 2

4
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);
}

试试这个功能,来自:http ://stolenpackets.net/?p=29

于 2013-01-25T22:13:59.660 回答
2

查看此代码没有涉及以太网数据包

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();
于 2013-01-11T09:28:25.997 回答