Skip to content

Instantly share code, notes, and snippets.

@arcatdmz
Created February 20, 2022 03:05
Show Gist options
  • Save arcatdmz/54c614b7668e422711f106cbb7d8cc35 to your computer and use it in GitHub Desktop.
Save arcatdmz/54c614b7668e422711f106cbb7d8cc35 to your computer and use it in GitHub Desktop.
Test if destination IPs are serving HTTP service or not.
// 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