SharpPcap中文开发全攻略Word下载.docx
《SharpPcap中文开发全攻略Word下载.docx》由会员分享,可在线阅读,更多相关《SharpPcap中文开发全攻略Word下载.docx(21页珍藏版)》请在冰豆网上搜索。
NET应用WinPcap而在他的大学最后项目的工作。
TheprojectinvolvedanalyzinganddecodingVoIPtrafficandhewantedtokeepcodingsimplewithC#whichhastimesavingfeatureslikegarbagecollection.该项目涉及VoIP流量分析和解码,他想继续用C#编码具有省时,如垃圾收集功能简单。
AccessingtheWinPcapAPIfrom.NETseemedtobequiteapopularrequirement,andhefoundsomeusefulprojectsonCodeProject'
swebsitethatletyoudojustthat:
WinPcap的API的访问似乎从净是相当流行的要求,他发现在CodeProject上的一些网站,让您做到这一点有益的项目。
:
PacketCaptureandAnalyzer数据包捕获和分析仪
RawSocketCapturingUsingC#原始套接字捕获使用C#
Packetsniffingwithwinpcapfunctionsportedtoa.NETlibrary与WinPcap的包嗅探功能移植到。
NET库
Thefirstprojectisagreatethereal.NETclonethatletsyoucaptureandanalyzenumeroustypesofprotocolpackets.第一个项目是一个伟大的空灵。
NET的克隆,让您获取和分析大量的数据包的协议类型。
However,afewissueswiththisprojectmakeitalmostimpossibletobesharedamongother.NETapplications.然而,随着这个项目的几个问题使它几乎不可能得到在其他。
NET应用程序共享。
Firstly,theauthordidnotprovideanygenericAPIforcapturingpacketsthatcanbeusedbyother.NETapplications.首先,作者没有提供用于捕获,可以通过其他。
NET应用程序中使用任何通用的API包。
Hedidn'
tseparatehisUIcodeandhisanalyzingandcapturingcode,makinghiscapturingcodedependontheGUIclassessuchasListViewtooperate.他没有单独的UI代码和他的分析和捕获的代码,使他的捕捉代码类依赖于图形用户界面,如ListView操作。
Secondly,forsomereasontheauthorchosetore-implementsomeofWinPcap'
sfunctionsinC#byhimselfratherthanjustwrappingthem.其次,由于某些原因,笔者选择了重新实现在C#由他本人,而不是仅仅WinPcap的包装他们的部分职能。
Thismeansthathisapplicationcan'
ttakeadvantageofthenewWinPcapversionssincehehardcodedacertainversionofWinPcapinhisapplication.这意味着他的应用程序无法利用新的WinPcap的版本的硬编码的优势,因为他在他的WinPcap的应用程序的某些版本。
ThesecondandthethirdarticlesarenicestartsforwrapperprojectsforWinPcap,howevertheydidn'
tprovidesomeimportantWinPcapfeaturessuchashandlingofflinepcapfilesandapplyingkernel-levelpacketfilters,andmostimportantlytheyprovidenoparserclassesforanalyzingprotocolpackets.第二个和第三个物品的包装项目为WinPcap的好开始,但他们没有提供一些重要的WinPcap的功能,如离线pcap的文件处理和应用内核级数据包过滤器,以及最重要的是他们提供了这样的分析没有协议分析器类包。
Bothprojectsdidn'
tposttheirlibrarysourcecodetogetherwiththearticleinordertoletotherpeopleextendtheirworkandaddnewfeaturesandnewpacketparserclasses.这两个项目没有张贴的文章,以自己的库的源代码,让其他人一起延长他们的工作和增加新功能和新的数据包分析器类。
Andso,Tamirdecidedtostarthisownlibraryforthetask.因此,塔米尔决定开始他对自己的图书馆工作。
Severalversionsintheserieswerereleased.在系列的几个版本发布。
Developmentslowedtowardsmid-2007whenthelastversionintheserieswasreleased,SharpPcap发展放缓对2007年年中时,在系列的最后一个版本发布时,SharpPcap。
ChrisMorgantookoverdevelopmentofSharpPcapinNovemberof2008.克里斯摩根发生在2008年11月超过SharpPcap发展。
SincethenSharpPcaphashadmajorinternalrewritesandAPIimprovements.从那时起SharpPcap主要内部已重写和API改进。
InlateFebruary2010,SharpPcapwasreleased.2010年2月下旬,SharpPcap被释放。
ThisreleaserepresentsarewriteofSharpPcap'
spacketparsers.此版本是一个重写SharpPcap的数据包分析器。
Packetparsingfunctionalitywasbrokenoutintoanewlibrary,.分组分析功能被打破,进入一个新的图书馆,。
SharpPcaptakescareofinterfacingwithlibpcap/winpcapandtakescareofpacketdissectionandcreation.SharpPcap注意到与libpcap的/WinPcap的包和注意到接口解剖和创造护理照顾。
Thedetailsof'
sarchitecturewillbediscussedlaterinthetutorial.对的建筑的细节将在本教程的后面讨论。
SharpPcapwasreleasedFebruary1st,2011.SharpPcap版本发布了2月1日,2011年。
ThereleasecontainssignificantAPIchangesaswellasWinPcapremotecaptureandAirPcapsupport.版本包含重大的空气污染指数的变化以及WinPcap的远程采集和支持AirPcap。
AboutSharpPcap关于SharpPcap
ThepurposeofSharpPcapistoprovideaframeworkforcapturing,injectingandanalyzingnetworkpacketsfor.NETapplications.的目的SharpPcap是提供一个框架NET应用程序捕获,注资。
和分析网络数据包。
SharpPcapisopenlyandactivelydevelopedwithitssourcecodeandfilereleaseshostedonSourceForge.SharpPcap是公开和积极发展同它的源代码和文件发布在SourceForge托管。
Sourcecodepatchestoimproveorfixissuesarewelcomeviathesharppcapdevelopersmailinglist.源代码补丁,以改善或解决问题欢迎通过sharppcap开发者邮件列表。
Bugreports,featurerequestsandotherqueriesareactivelyansweredonthesupportforumsandissuetrackerstheresoifyouhaveanytroublewiththelibrarypleasefeelfreetoask.错误报告,功能要求和其他查询正在积极回答问题的论坛和跟踪支持,所以如果你有任何问题请与库随时问。
SharpPcapisafullymanagedcrossplatformlibrary.SharpPcap是一个完全跨平台的库管理。
ThesameassemblyrunsunderMicrosoft.NETaswellasMonoonboth32and64bitplatforms.同一程序集运行在微软的。
NET以及单在32位和64位平台。
ThefollowinglistillustratesthefeaturescurrentlysupportedbySharpPcap:
下面的列表说明了目前SharpPcap功能支持:
SingleassemblyforMicrosoft.NETandMonoplatformsonWindows(32or64bit),Linux(32or64bit)andMac.单一组件的Microsoft。
NET和Mono平台上的Windows(32位或64位)和Linux(32或64位)和Mac。
Highperformance-SharpPcapcancapturefastenoughtokeepupwith>
3MB/sscptransferrates高性能-SharpPcap可以捕捉足够快跟上>
的3MB/s的传输速率高达SCP的
WinPcapextensionsarepartiallysupported:
WinPcap的扩展部分支持:
oSettingthekernelbuffersize设置内核缓冲区大小
oInjectingpacketsusingsendqueues.注射用的数据包发送队列。
oCollectingnetworkstatisticsonagivennetworkinterface收集在一个特定的网络接口的网络统计
AirPcapsupportAirPcap支持
EnumeratingandshowingdetailsaboutthephysicalnetworkinterfaceonaWindowsmachine.枚举和显示有关Windows机器上的物理网络接口的细节。
Capturinglow-levelnetworkpacketsgoingthroughagiveninterface.捕获低级别的网络数据包将通过给定的接口。
Analyzingandparsingthefollowingprotocols:
分析和解析以下协议:
oEthernet以太网
oSLL(LinuxCooked-ModeCapture)血清瘦素(Linux的熟食方式采集)
oARP(AddressResolutionProtocol)ARP(地址解析协议)
oIP(InternetProtocol):
IP(因特网协议):
IPv4IPv4的
IPv6IPv6的
oTCP(TransmissionControlProtocol)TCP(传输控制协议)
oUDP(UserDatagramProtocol)UDP(用户数据报协议)
oICMP(InternetControlMessageProtocol):
ICMP协议(Internet控制消息协议):
ICMPv4ICMPv4
ICMPv6ICMPv6报
oIGMPv2IGMPv2的
oPPPoEPPPoE协议
oPTP和平之路
oLLDPLLDP功能
oWake-on-LAN(WOL)唤醒局域网(网络唤醒)
Injectinglow-levelnetworkpacketsonagiveninterface.在给定接口注入的低级别的网络数据包。
Handling(readingandwriting)offlinepacketcapturefiles.处理(阅读和写作)离线数据包捕获文件。
Retrievingadapterstatisticsonpacketsreceivedvs.dropped检索的数据包接收适配器统计对比下降
Pleasechecktheprojecthomepagehomepageforthelatestupdatesandbugfixes.请检查项目主页主页最新的更新和bug修复。
SharpPcaparchitectureSharpPcap架构
SharpPcaphasalayeredarchitecture,atthetoplevelareclassesthatworkacrossalldevices:
SharpPcap具有层状结构,在顶层的类,所有设备的工作:
CaptureDeviceList-RetrievesalistofalldevicesonthesystemCaptureDeviceList-检索系统名单上的所有设备
OfflineCaptureDevice-DevicethatreadsfromapcapcapturefileOfflineCaptureDevice-文件读取装置从一个pcap的捕捉
ICaptureDevice-AllcapturedeviceshaveICaptureDeviceinterfacesICaptureDevice-所有的捕捉设备有ICaptureDevice接口
Thenamespacesarelayedouthierarchically:
该命名空间的布局层次:
LibPcaplibpcap的
oLibPcapLiveDevice-AnICaptureDeviceLibPcapLiveDevice-一个ICaptureDevice
oLibPcapLiveDeviceList-RetrievesalistofLibPcapLiveDevicedevices(theseincludepcap/winpcapandairpcapdevices)LibPcapLiveDeviceList-检索一个名单LibPcapLiveDevice设备(其中包括pcap的/WinPcap的和airpcap设备)
WinPcapWinPcap的
oWinPcapDeviceList-RetrievesalistofWinPcapDevices(theseincludewinpcapandairpcapdevices)WinPcapDeviceList-检索一个名单WinPcapDevices(其中包括WinPcap的和airpcap设备)
oWinPcapDevice-ALibPcapLiveDevicewithadditionalWinPcapfeaturesandinterfacesWinPcapDevice-阿LibPcapLiveDevice额外WinPcap的功能和接口
AirPcapAirPcap
oAirPcapDeviceList-RetrievesalistofAirPcapDevicesAirPcapDeviceList-检索一个名单AirPcapDevices
oAirPcapDevice-AWinPcapDevicewithadditionalAirPcapfeaturesandinterfacesAirPcapDevice-阿WinPcapDevice额外AirPcap功能和接口
CaptureDeviceListreturnsalistoffullydifferentiated返回一个设备清单完全分化。
ThismeansthateachICaptureDevicereturnedbyCaptureDeviceListiseitheraLibPcapLiveDevice,aWinPcapDeviceoraAirPcapDevice.这意味着每个ICaptureDevice由归国CaptureDeviceList要么是LibPcapLiveDevice,一WinPcapDevice或AirPcapDevice。
Thisallowsyoutoretrievetheentirelistofdevicesanddifferentiatebylookingatthetypeofeachdevice.这使您可以检索整个列表的设备和差异化在每个设备类型看。
Ifyouwouldliketogetaspecifictypeofdeviceonly,youcanuseoneoftheparticular*DeviceListclasses.如果你想获得一个特定的特定类型的设备只,你可以使用一个*DeviceList类。
Collapse|CopyCode
切换从到SharpPcap继承模型的嵌套包之一。
AllpacketscontainaPacketPayloadPacketpropertyandaByte[]PayloadDataproperty.所有的数据包包含一个PacketPayloadPacket属性和一个Byte[]PayloadData财产。
Oneorneitherofthesecanbevalid.一个或多个这些都不能有效。
ATCPpacketcapturedonEthernetmaybeEthernetPacket->
IPv4Packet->
TcpPacket.以太网上的TCP数据包捕获的可能EthernetPacket“->
IPv4包->
”TCP数据包。
In,theTCPpacketcouldbeaccessedlikebuttoaidusersstaticGetEncapsulsted()methodshavebeenaddedsouserscandovartcpPacket=(capturedPacket);
.在时,TCP数据包可能被访问一样而是要帮助用户从staticGetEncapsulsted()方法被添加,因此用户可以做的vartcpPacket=(capturedPacket);
。
TheGetEncapsulated()methodsareintelligentanddesignedtoworkinmanydiff