到目前为止,我尝试使用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类.
解决方法
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); }