我怎么知道RawCapture数据包的类型. [英] how can I know the type of RawCapture packet.
本文介绍了我怎么知道RawCapture数据包的类型.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道RawCapture数据包的类型(如果是Tcp或UDP).
如何开始?
I would like to know the type of RawCapture packet (if it''s Tcp or UDP).
how can I start?
推荐答案
开始 ^ ];您可以对UDP执行相同操作.
Start here[^]; you can do the same for UDP.
如果允许使用第三方库,请尝试Winpcap库是执行此操作的最佳方法之一.
www.winpcap.org/ [ ^ ]
Hi,
if you are allowed to use a third party library try The Winpcap library is one of the best ways to do this.
www.winpcap.org/[^]
非常感谢.
我有解决方案:
Thank you so much.
I have got the solution:
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数据包的类型.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文