Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

specify-source-address-and-port.js 1014B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2013 Stephen Vickers
  2. var snmp = require ("../");
  3. if (process.argv.length < 8) {
  4. console.log ("usage: specify-source-address-and-port <source-address> "
  5. + "<source-port>\n <target> <community> <version> "
  6. + "<oid>");
  7. process.exit (1);
  8. }
  9. var sourceAddress = process.argv[2];
  10. var sourcePort = process.argv[3];
  11. var target = process.argv[4];
  12. var community = process.argv[5];
  13. var version = (process.argv[6] == "2c") ? snmp.Version2c : snmp.Version1;
  14. var oids = [process.argv[7]];
  15. var sessionOptions = {
  16. version: version,
  17. sourceAddress: sourceAddress,
  18. sourcePort: sourcePort
  19. };
  20. var session = snmp.createSession (target, community, sessionOptions);
  21. session.get (oids, function (error, varbinds) {
  22. if (error) {
  23. console.error (error.toString ());
  24. } else {
  25. for (var i = 0; i < varbinds.length; i++) {
  26. if (snmp.isVarbindError (varbinds[i]))
  27. console.error (snmp.varbindError (varbinds[i]));
  28. else
  29. console.log (varbinds[i].oid + "|" + varbinds[i].value);
  30. }
  31. }
  32. });