本文介绍了我怎么知道RawCapture数据包的类型.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道RawCapture数据包的类型(如果是Tcp或UDP).
如何开始?
I would like to know the type of RawCapture packet (if it''s Tcp or UDP).
how can I start?
推荐答案
EthernetPacket eth = EthernetPacket.ParsePacket(pack.LinkLayerType, pack.Data) as EthernetPacket;
if (eth != null)
{
String macsrc = eth.SourceHwAddress.ToString();
String macdest = eth.DestinationHwAddress.ToString();
protocol = "Ethernet";
IPv4Packet ipv4Packet = eth.PayloadPacket as IPv4Packet;
if(ipv4Packet != null)
{
String ipsrc = ipv4Packet.SourceAddress.ToString();
String ipdest = ipv4Packet.DestinationAddress.ToString();
//protocol += "-IPv4 ("+ipv4Packet .SourceAddress .ToString()+"->"+ipv4Packet .DestinationAddress .ToString ()+")";
protocol +="_IPv4";
UdpPacket udpPacket = ipv4Packet.PayloadPacket as UdpPacket;
if (udpPacket != null)
{
String portSrcUdp = udpPacket.SourcePort.ToString();
String portDestUdp = udpPacket.DestinationPort.ToString();
protocol += "-UDP";
this.AllPackets.Rows.Add(packetCount.ToString(), len.ToString(), timestr, protocol, macsrc, macdest, ipsrc, ipdest, portSrcUdp, portDestUdp);
continue;
}
...
效果很好:)
It works good :)
这篇关于我怎么知道RawCapture数据包的类型.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!