-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-service.js
executable file
·89 lines (79 loc) · 2.48 KB
/
test-service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env node
const { performance } = require('perf_hooks'); // Node.js performance API
const http = require('http'); // Node.js native HTTP module
const DOMAINS = [
// real domains
"google.com",
"microsoft.com",
"apple.com",
"amazon.com",
"facebook.com",
"salesforce.com",
"ibm.com",
"oracle.com",
"adobe.com",
"spotify.com",
"twitter.com",
"linkedin.com",
"netflix.com",
"airbnb.com",
"uber.com",
"slack.com",
"zoom.us",
"github.com",
"dropbox.com",
"atlassian.com",
// fake domains
"alphanode.cloud",
"gigabytecraft.tech",
"cloudstack.io",
"corsair-systems.com",
"cybermatrix24.dev",
"dataforge.tech",
"deltacloud.org",
"ethereality.co",
"fusion-tech.lol",
"hypermail.io",
"infinitymailing.io",
"nexusmail.net",
"novacorp.co",
"omnisphere.co",
"pulse-networks.org",
"quantumhost.cloud",
"stellarcloud.net",
"synthetica.dev",
"vertex-systems.dev",
"zenithmail.io",
];
const TARGET = "spf.protection.outlook.com";
const BASE_URL = "http://localhost:8080/api/v1/check-spf";
async function checkSpf(domain) {
const start = performance.now();
const url = `${BASE_URL}?domain=${domain}&target=${TARGET}`;
return new Promise((resolve) => {
http.get(url, (response) => {
const duration = (performance.now() - start).toFixed(2);
let data = '';
response.on('data', (chunk) => {
data += chunk;
});
response.on('end', () => {
const jsonData = JSON.parse(data);
if (response.statusCode > 299) {
console.log(`${domain}: ${duration}ms (error: ${jsonData.error})`);
} else {
console.log(`${domain}: ${duration}ms (reported: ${jsonData.elapsed_ms ?? '-'}) - Found: ${jsonData.found ?? '-'} (checked ${jsonData.checked_domains ?? 'no'} domains)`);
}
resolve();
});
}).on('error', (error) => {
console.error(`Error checking ${domain}: ${error.message}`);
resolve(); // Resolve the promise even if there's an error
});
});
}
console.log(`Testing parallel SPF checks for target: ${TARGET}\n`);
// Execute all checks in parallel
Promise.all(DOMAINS.map(domain => checkSpf(domain)))
.then(() => console.log("\nAll checks completed"))
.catch(error => console.error("Error during execution:", error));