initial commit

This commit is contained in:
2022-06-29 16:10:24 +02:00
commit 63af500747
11 changed files with 5984 additions and 0 deletions

1
dist/bundle.js vendored Normal file
View File

@@ -0,0 +1 @@
(()=>{"use strict";const e=require("ip-cidr"),r=require("readline"),t=require("getopts"),n=require("net-snmp");function o(e,r){return new Promise(((t,o)=>{const i=[];e.subtree(r,20,(e=>{for(let r=0;r<e.length;r++)n.isVarbindError(e[r])?o(n.varbindError(e[r])):i.push(e[r].value.toString())}),(e=>{e&&o(e),t(i)}))}))}function i(e,r,t,i,s){return c=this,u=void 0,l=function*(){const c=n.createSession(e.address,t,{retries:i,timeout:s,version:"2c"===r?n.Version2c:n.Version1,transport:e.v4?"udp4":"udp6"});try{const r=yield function(e,r){return new Promise(((r,t)=>{e.get(["1.3.6.1.2.1.1.5.0"],((e,o)=>{e?t(e):o.length?n.isVarbindError(o[0])?t(n.varbindError(o[0])):r(o[0].value.toString()):r("")}))}))}(c);let t=yield o(c,"1.3.6.1.2.1.31.1.1.1.1");t.length||(t=yield o(c,"1.3.6.1.2.1.2.2.1.2")),c.close(),console.log(`${e.address}; ${r}; ${t.join(", ")}`)}catch(r){r instanceof n.RequestTimedOutError||console.error(`Error: ${e.address} ${r}`)}},new((a=void 0)||(a=Promise))((function(e,r){function t(e){try{o(l.next(e))}catch(e){r(e)}}function n(e){try{o(l.throw(e))}catch(e){r(e)}}function o(r){var o;r.done?e(r.value):(o=r.value,o instanceof a?o:new a((function(e){e(o)}))).then(t,n)}o((l=l.apply(c,u||[])).next())}));var c,u,a,l}const s=t(process.argv.slice(2),{alias:{version:"v",community:"c",retries:"r",timeout:"t",delay:"d"}}),c=s.version?s.version:"1",u=s.community?s.community:"public",a=s.retries?Number(s.retries):2,l=s.timeout?Number(s.timeout):1500,d=s.delay?Number(s.delay):20;console.log(`SNMP version: ${c}, Community: ${u}, Retries: ${a}, Timeout: ${l} ms, Delay: ${d} ms`),console.log("---");const m=r.createInterface({input:process.stdin,output:process.stdout,terminal:!1});m.on("line",(r=>{return t=void 0,n=void 0,s=function*(){try{const t=new e(r);for(const e of t.toArray({type:"addressObject"}))yield new Promise((e=>setTimeout(e,d))),i(e,c,u,a,l)}catch(e){console.error(e)}m.close()},new((o=void 0)||(o=Promise))((function(e,r){function i(e){try{u(s.next(e))}catch(e){r(e)}}function c(e){try{u(s.throw(e))}catch(e){r(e)}}function u(r){var t;r.done?e(r.value):(t=r.value,t instanceof o?t:new o((function(e){e(t)}))).then(i,c)}u((s=s.apply(t,n||[])).next())}));var t,n,o,s}))})();