snmp4j初学代码
代码说明:
简单的连接snmp agent 然后get数据 在main函数中 Address targetAddress=GenericAddress.parse("udp:192.168.5.151/161"); TransportMapping transport=new DefaultUdpTransportMapping(); Snmp snmp=new Snmp(transport); transport.listen(); CommunityTarget target=new CommunityTarget(); target.setCommunity(new OctetString("WinSpread")); target.setAddress(targetAddress); target.setRetries(3); target.setTimeout(5000); target.setVersion(1); PDU request=new PDU(); request.setType(PDU.SET); // request.add(new VariableBinding(new OID("IP-FORWARD-MIB::inetCidrRouteMetric4.ipv4"))); // request.add(new VariableBinding(new OID("IP-MIB::ipAdEntAddr"))); // request.add(new VariableBinding(new OID(".1.3.6.1.2.1.1.3.0"))); //
下载说明:请别用迅雷下载,失败请重下,重下不扣分!