关于用C#进行SNMP协议编程161端口是默认的,也就是设备上开的端口,而162端口是本机开的端口。snmp协议是通过udp协议的,所以是不而向连接的。网上有关于winsnmp方面的资料,述有就是现在有很多代码提供了对.net的支持国外已经有高手导出wsnmp.dll的API了,有三个文件:Functions・cs,Enumns・cs,structs.cs。Functions・csusingSystem;usingSystem.Runtime・InteropServices;namespaceWinSnmp{III///SnmpAPIFunctionsIIIpublicclassSnmpAPI{//CallbackpublicdelegateSNMPAPI_STATUSSnmpCallback(IntPtrsession,IntPtrhwnd,intmsg,uintwparam,uintlparam,IntPtrdata);//Communicationfunctions[D111mport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpStartup(outintmajor,outintminor,outintlevel,outinttranslate,outintretransmit);[Dlllmport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpCleanup();[Dlllmport(wsnmp32.dll)]publicstaticexternIntPtrSnmpCreateSession(IntPtrhwndJntmsg,SnmpCallbackcallback,IntPtrdata);[Dlllmport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpClose(IntPtrsession);[Dlllmport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpRegister(IntPtrsessionJntPtrsrcJntPtrclestJntPtrcontextJntPtrnotificationJntstate);[Dlllmport(wsnmp32.dll)]publiestaticexternSNMPAPI_STATUSSnmpListen(IntPtrentity,IntPtrstatus);[Dlllmport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpSendMsg(IntPtrsessionJntPtrsrcJntPtrdest,IntPtrcontextJntPtrpdu);[Dlllmport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpRecvMsg(IntPtrsession,outIntPtrsrc,outIntPtrdcst,outIntPtrcontcxt5outIntPtrpdu);publicstaticexternSNMPAPI_STATUSSnmpCancelMsg(IntPtrsession,IntPtrreqid);//EntityandContextfunctions[Dillmport(wsnmp32.dll)]publicstaticexternSNMPAPl_STATUSSnmpContextToStr(IntPtrcontext,refSMIOCTETSoctets);[Dlllmport(wsnmp32.dll)]publicstaticexternIntPtrSnmpStrToContext(IntPtrsession,refSMIOCTETSoctets);[Dlllmport(wsnnip32.dll)]publicstaticexternSNMPAPI_STATUSSnmpFreeEntity(IntPtrentity);[Dlllmport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpEntityToStr(IntPtrentity,intsize,IntPtrstr);[Dillmport(wsnmp32.dll)]publicstaticexternlntPtrSnmpStrToEntity(IntPtrsession,[MarshalAs(UnmanagedType.LPStr)]stringstr);[DllImport(wsnmp32.dll)JpublicstaticcxtcrnSNMPAPI_STATUSSnmpFrccContcxt(IntPtrcontcxt);publicstaticexternSNMPAPI_STATUSSnmpSetPort(IntPtrentity,intport);//Databasefunetions[DllImport(wsnmp32.dll)JpublicstaticexternSNMPAPI_STATUSSnmpGetRetransmitMode(outuintiTiode)[Dlllmport(wsnnip32.dll)]publicstaticexternSNMPAPI_STATUSSnmpGetRetry(IntPtrentity,outuintpolicy5outuintactual);[Dlllmport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpGetTimeout(IntPtrentity,outintpolicy,outintactual);[Dlllmport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpGetTranslateMode(outuintmode);[Dlllmport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpGetVendorInfo(refVENDORINFOInfo);[Dlllmport(wsnmp32.dll)]publicstaticcxtcrnSNMPAPI_STATUSSnmpSctRctransmitModc(SNMPAPI_RETRANSMITmode);pubIicstaticexternSNMPAPI_STATUSSnmpSetRetry(IntPtrentityJntpoIicy);[Dllimport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpSetTimeout(IntPtrentity,intpolicy)[Dlllmport(wsnmp32.dll)]publicstaticexternSNMPAPI_STATUSSnmpSetTransIateMode(SNMPAPI_TRANSLATEmode);//PDUfunctions[Dlllmport(wsnmp32.dll)]publicstaticexternIntPtrSnmpCreatePdu(IntPtrsession,inttype,intreqid,intstatusJntindexJntPtrvblist);[Dlllmport(wsnmp32.dll)]publicstaticexternIntPtrSnmpDuplicatePdu(IntPtrsessionJntP...