This repository has been archived on 2022-10-07. You can view files and clone it, but cannot push or open issues or pull requests.
2021-05-05 12:18:10 +00:00
|
|
|
const http = require("http");
|
2022-02-07 14:57:24 +00:00
|
|
|
const { ipCheckService, ipRegex } = require("./utils");
|
2021-05-05 12:18:10 +00:00
|
|
|
|
2022-02-07 14:57:24 +00:00
|
|
|
const request = http.request({ host: ipCheckService }, (response) => {
|
2021-05-05 12:18:10 +00:00
|
|
|
response.on("data", (data) => {
|
2022-02-07 14:57:24 +00:00
|
|
|
if (ipRegex.test(data)) {
|
|
|
|
process.stdout.write(data);
|
|
|
|
} else {
|
|
|
|
throw new Error(`${ipCheckService} responded with invalid ip: "${data}"`);
|
|
|
|
}
|
2021-05-05 12:18:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
request.on("error", (error) => {
|
2022-02-07 14:57:24 +00:00
|
|
|
throw error; // throw error to exit with code 1
|
2021-05-05 12:18:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
request.end();
|