Advertisement
Guest User

Untitled

a guest
May 25th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const cidrTools = require("cidr-tools");
  2. const ping = require("ping");
  3.  
  4. const hosts = cidrTools.expand("10.0.1.0/24");
  5. const alive = [];
  6.  
  7. Promise.all(
  8.   hosts.map(host => {
  9.       ping.promise.probe(host).then((res) => {
  10.           if (res.alive) {
  11.               console.log(res.host)
  12.         }
  13.     });
  14.   })
  15. );
  16.  
  17. console.log(alive);
  18. console.log(`done`);
  19.  
  20. // Result
  21. []
  22. done
  23. 10.0.1.196
  24. 10.0.1.192
  25. 10.0.1.187
  26. 10.0.1.153
  27. 10.0.1.150
  28. 10.0.1.138
  29. 10.0.1.25
  30. 10.0.1.20
  31. 10.0.1.14
  32. 10.0.1.13
  33. 10.0.1.12
  34. 10.0.1.11
  35. 10.0.1.10
  36. 10.0.1.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement