发送虚假构造的伪IP的UDP数据包。
构造数据包经常出错!!!原因是很多属性没设置好。。我调试了很多次才发送成功!!!
private void SendPacket()
{
string strGateWayIp = "192.168.100.1";
string strSouMac = new Class1().GetMACFromIP("192.168.100.106");//
PcapDeviceList allDevices = SharpPcap.GetAllDevices();
PcapDevice device = allDevices[0];
NetworkDevice device2 = (NetworkDevice)device;
int lLen = EthernetFields_Fields.ETH_HEADER_LEN;
string strGateWayMac = new Class1().GetMACFromIP(strGateWayIp);// zfrong
byte[] bytes = new byte[60];
UDPPacket p = new UDPPacket(lLen, bytes);//
p.EthernetProtocol = EthernetProtocols_Fields.IP;
p.IPVersion = IPVersions_Fields.IPV4;
p.IPProtocol = IPProtocols_Fields.UDP;//
p.TimeToLive = 2;//
p.IPHeaderLength = IPFields_Fields.IP_HEADER_LEN;//
p.Length = 60;//
p.SourceHwAddress = strSouMac;
p.DestinationHwAddress = strGateWayMac;
p.SourceAddress = "201.23.12.88";
p.SourcePort = 12345;
p.DestinationAddress = "192.168.100.106";
p.DestinationPort = 9000;
p.ComputeIPChecksum(true);//
p.ComputeUDPChecksum(true);
int k=0;
while(k<20)
{
device2.PcapOpen(true, 200);
device2.PcapSendPacket(p); k++;
device2.PcapClose();
}
}