@Ignore @Test public void testSnmpSyncGetList() { SnmpSimpleGet.snmpSyncGetList(ip, "public", oids); try { snmpV2sysORDescr1(); } catch (Exception e) { throw new RuntimeException(e); } }
public static void snmpSyncGetList(String ip, String community, List<String> oidList) { CommunityTarget target = createDefault(ip, community); Snmp snmp; try { DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping(); snmp = new Snmp(transport); snmp.listen(); PDU pdu = new PDU(); for (String oid : oidList) { pdu.add(new VariableBinding(new OID(oid))); } final CountDownLatch latch = new CountDownLatch(1); ResponseListener listener = new ResponseListener() { @Override public void onResponse(ResponseEvent event) { ((Snmp) event.getSource()).cancel(event.getRequest(), this); PDU response = event.getResponse(); PDU request = event.getRequest(); System.out.println("[request]:" + request); if (response == null) { System.out.println("[ERROR]: response is null"); } else if (response.getErrorStatus() != 0) { System.out.println("[ERROR]: response status" + response.getErrorStatus() + " Text:" + response.getErrorStatusText()); } else { System.out.println("Received response Success!"); for (int i = 0; i < response.size(); i++) { VariableBinding vb = response.get(i); System.out.println(vb.getOid() + " = " + vb.getVariable()); } System.out.println("SNMP Async GetList OID finished. "); latch.countDown(); } } }; pdu.setType(PDU.GET); snmp.send(pdu, target, null, listener); System.out.println("async send pdu wait for response..."); boolean wait = latch.await(5, TimeUnit.SECONDS); System.out.println("latch.await =:" + wait); snmp.close(); } catch (Exception e) { throw new RuntimeException(e); } }
SnmpSimpleGet { public static void snmpSyncGetList(String ip, String community, List<String> oidList) { CommunityTarget target = createDefault(ip, community); Snmp snmp; try { DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping(); snmp = new Snmp(transport); snmp.listen(); PDU pdu = new PDU(); for (String oid : oidList) { pdu.add(new VariableBinding(new OID(oid))); } final CountDownLatch latch = new CountDownLatch(1); ResponseListener listener = new ResponseListener() { @Override public void onResponse(ResponseEvent event) { ((Snmp) event.getSource()).cancel(event.getRequest(), this); PDU response = event.getResponse(); PDU request = event.getRequest(); System.out.println("[request]:" + request); if (response == null) { System.out.println("[ERROR]: response is null"); } else if (response.getErrorStatus() != 0) { System.out.println("[ERROR]: response status" + response.getErrorStatus() + " Text:" + response.getErrorStatusText()); } else { System.out.println("Received response Success!"); for (int i = 0; i < response.size(); i++) { VariableBinding vb = response.get(i); System.out.println(vb.getOid() + " = " + vb.getVariable()); } System.out.println("SNMP Async GetList OID finished. "); latch.countDown(); } } }; pdu.setType(PDU.GET); snmp.send(pdu, target, null, listener); System.out.println("async send pdu wait for response..."); boolean wait = latch.await(5, TimeUnit.SECONDS); System.out.println("latch.await =:" + wait); snmp.close(); } catch (Exception e) { throw new RuntimeException(e); } } }
SnmpSimpleGet { public static void snmpSyncGetList(String ip, String community, List<String> oidList) { CommunityTarget target = createDefault(ip, community); Snmp snmp; try { DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping(); snmp = new Snmp(transport); snmp.listen(); PDU pdu = new PDU(); for (String oid : oidList) { pdu.add(new VariableBinding(new OID(oid))); } final CountDownLatch latch = new CountDownLatch(1); ResponseListener listener = new ResponseListener() { @Override public void onResponse(ResponseEvent event) { ((Snmp) event.getSource()).cancel(event.getRequest(), this); PDU response = event.getResponse(); PDU request = event.getRequest(); System.out.println("[request]:" + request); if (response == null) { System.out.println("[ERROR]: response is null"); } else if (response.getErrorStatus() != 0) { System.out.println("[ERROR]: response status" + response.getErrorStatus() + " Text:" + response.getErrorStatusText()); } else { System.out.println("Received response Success!"); for (int i = 0; i < response.size(); i++) { VariableBinding vb = response.get(i); System.out.println(vb.getOid() + " = " + vb.getVariable()); } System.out.println("SNMP Async GetList OID finished. "); latch.countDown(); } } }; pdu.setType(PDU.GET); snmp.send(pdu, target, null, listener); System.out.println("async send pdu wait for response..."); boolean wait = latch.await(5, TimeUnit.SECONDS); System.out.println("latch.await =:" + wait); snmp.close(); } catch (Exception e) { throw new RuntimeException(e); } }  }
SnmpSimpleGet { public static void snmpSyncGetList(String ip, String community, List<String> oidList) { CommunityTarget target = createDefault(ip, community); Snmp snmp; try { DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping(); snmp = new Snmp(transport); snmp.listen(); PDU pdu = new PDU(); for (String oid : oidList) { pdu.add(new VariableBinding(new OID(oid))); } final CountDownLatch latch = new CountDownLatch(1); ResponseListener listener = new ResponseListener() { @Override public void onResponse(ResponseEvent event) { ((Snmp) event.getSource()).cancel(event.getRequest(), this); PDU response = event.getResponse(); PDU request = event.getRequest(); System.out.println("[request]:" + request); if (response == null) { System.out.println("[ERROR]: response is null"); } else if (response.getErrorStatus() != 0) { System.out.println("[ERROR]: response status" + response.getErrorStatus() + " Text:" + response.getErrorStatusText()); } else { System.out.println("Received response Success!"); for (int i = 0; i < response.size(); i++) { VariableBinding vb = response.get(i); System.out.println(vb.getOid() + " = " + vb.getVariable()); } System.out.println("SNMP Async GetList OID finished. "); latch.countDown(); } } }; pdu.setType(PDU.GET); snmp.send(pdu, target, null, listener); System.out.println("async send pdu wait for response..."); boolean wait = latch.await(5, TimeUnit.SECONDS); System.out.println("latch.await =:" + wait); snmp.close(); } catch (Exception e) { throw new RuntimeException(e); } }  static void snmpGet(String ip, String community, List<String> oids); static void snmpSyncGetList(String ip, String community,
                                       List<String> oidList); }
SnmpSimpleGet { public static void snmpSyncGetList(String ip, String community, List<String> oidList) { CommunityTarget target = createDefault(ip, community); Snmp snmp; try { DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping(); snmp = new Snmp(transport); snmp.listen(); PDU pdu = new PDU(); for (String oid : oidList) { pdu.add(new VariableBinding(new OID(oid))); } final CountDownLatch latch = new CountDownLatch(1); ResponseListener listener = new ResponseListener() { @Override public void onResponse(ResponseEvent event) { ((Snmp) event.getSource()).cancel(event.getRequest(), this); PDU response = event.getResponse(); PDU request = event.getRequest(); System.out.println("[request]:" + request); if (response == null) { System.out.println("[ERROR]: response is null"); } else if (response.getErrorStatus() != 0) { System.out.println("[ERROR]: response status" + response.getErrorStatus() + " Text:" + response.getErrorStatusText()); } else { System.out.println("Received response Success!"); for (int i = 0; i < response.size(); i++) { VariableBinding vb = response.get(i); System.out.println(vb.getOid() + " = " + vb.getVariable()); } System.out.println("SNMP Async GetList OID finished. "); latch.countDown(); } } }; pdu.setType(PDU.GET); snmp.send(pdu, target, null, listener); System.out.println("async send pdu wait for response..."); boolean wait = latch.await(5, TimeUnit.SECONDS); System.out.println("latch.await =:" + wait); snmp.close(); } catch (Exception e) { throw new RuntimeException(e); } }  static void snmpGet(String ip, String community, List<String> oids); static void snmpSyncGetList(String ip, String community,
                                       List<String> oidList);  }