资源描述:
《关于用c#进行snmp协议编程》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、关于用C#进行SNMP协议编程161端口是默认的,也就是设备上开的端口,而162端口是本机开的端口。snmp协议是通过udp协议的,所以是不而向连接的。网上有关于winsnmp方面的资料,述有就是现在有很多代码提供了对.net的支持国外已经有高手导出wsnmp.dll的API了,有三个文件:Functions・cs,Enumns・cs,structs.cs。Functions・csusingSystem;usingSystem.Runtime・InteropServices;namespaceWinSnmp{III///SnmpAPIFunctionsIII
2、publicclassSnmpAPI{//CallbackpublicdelegateSNMPAPI_STATUSSnmpCallback(IntPtrsession,IntPtrhwnd,intmsg,uintwparam,uintlparam,IntPtrdata);//Communicationfunctions[D111mport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpStartup(outintmajor,outintminor,outintlevel,outinttranslate,ou
3、tintretransmit);[Dlllmport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpCleanup();[Dlllmport(wsnmp32.dll)]publicstaticexternIntPtrSnmpCreateSession(IntPtrhwndJntmsg,SnmpCallbackcallback,IntPtrdata);[Dlllmport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpClose(IntPtrsession)
4、;[Dlllmport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpRegister(IntPtrsessionJntPtrsrcJntPtrclestJntPtrcontextJntPtrnotificationJntstate);[Dlllmport(wsnmp32.dll)]publiestaticexternSNMPAPI_STATUSSnmpListen(IntPtrentity,IntPtrstatus);[Dlllmport(wsnmp32.dll)]publicstaticexternSN
5、MPAPI_STATUSSnmpSendMsg(IntPtrsessionJntPtrsrcJntPtrdest,IntPtrcontextJntPtrpdu);[Dlllmport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpRecvMsg(IntPtrsession,outIntPtrsrc,outIntPtrdcst,outIntPtrcontcxt5outIntPtrpdu);publicstaticexternSNMPAPI_STATUSSnmpCancelMsg(IntPtrsession,I
6、ntPtrreqid);//EntityandContextfunctions[Dillmport(wsnmp32.dll)]publicstaticexternSNMPAPl_STATUSSnmpContextToStr(IntPtrcontext,refSMIOCTETSoctets);[Dlllmport(wsnmp32.dll)]publicstaticexternIntPtrSnmpStrToContext(IntPtrsession,refSMIOCTETSoctets);[Dlllmport(wsnnip32.dll)]publicstatic
7、externSNMPAPI_STATUSSnmpFreeEntity(IntPtrentity);[Dlllmport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpEntityToStr(IntPtrentity,intsize,IntPtrstr);[Dillmport(wsnmp32.dll)]publicstaticexternlntPtrSnmpStrToEntity(IntPtrsession,[MarshalAs(UnmanagedType.LPStr)]stringstr);[DllImpo
8、rt(wsnmp32.dll)Jpublicstat