forked from nccgroup/singularity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan.js
More file actions
54 lines (50 loc) · 1.83 KB
/
Copy pathscan.js
File metadata and controls
54 lines (50 loc) · 1.83 KB
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
function timeout(ms, promise,controller) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
controller.abort();
reject(new Error("timeout"))
}, ms)
promise.then(resolve, reject)
})
}
function scan(targetdata, duration) {
let sendDate = new Date().getTime();
var controller = new AbortController();//NO IE support
var signal = controller.signal;
timeout(duration, fetch(`http://${targetdata.address}:${targetdata.port}/`, {
mode: 'no-cors',
credentials: 'omit',
signal
}),controller)
.then(function (response) {
let receiveDate = new Date().getTime();
let result = {
"error": false,
"errorReason": null,
"start": sendDate,
"end": receiveDate,
"duration": (receiveDate - sendDate),
"target": targetdata
};
postMessage(result);
})
.catch(function (e) {
let receiveDate = (new Date()).getTime();
console.log(`Scanner: ${e.message} for ${targetdata.address}:${targetdata.port}.`);
let result = {
"error": true,
"errorReason": e.message,
"start": sendDate,
"end": receiveDate,
"duration": (receiveDate - sendDate),
"target": targetdata
};
postMessage(result);
// console.log(`Worker: Sending result: ${result.duration}`);
})
}
onmessage = function (message) {
// console.log(`Worker: Message received from main script: ${target.data.address}:${target.data.port}`);
scan(message.data.targetdata, message.data.timeout);
// console.log('Worker: Posting message back to main script');
}