Created
February 20, 2022 03:05
-
-
Save arcatdmz/54c614b7668e422711f106cbb7d8cc35 to your computer and use it in GitHub Desktop.
Test if destination IPs are serving HTTP service or not.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Test if destination IPs are serving HTTP service or not. | |
// Java: https://gist.github.com/arcatdmz/5012993 | |
const http = require("http"); | |
const urls = []; | |
for (i = 1; i < 256; i++) { | |
urls.push(`http://192.168.1.${i}`); | |
} | |
function request(url) { | |
return new Promise((resolve) => { | |
http | |
.get(url, (res) => { | |
let body = ""; | |
res.setEncoding("utf8"); | |
res.on("data", (chunk) => { | |
body += chunk; | |
}); | |
res.on("end", () => { | |
resolve({ url, body }); | |
}); | |
}) | |
.on("error", (error) => { | |
resolve({ url, error: error.message || error }); | |
}); | |
}); | |
} | |
Promise.all(urls.map(request)).then((results) => { | |
console.log( | |
results | |
.map((result) => (typeof result.body === "string" ? `ok ${result.url}` : `ng ${result.url} ${result.error || "unknown error"}`)) | |
.join("\n") | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment