forked from dxa4481/logger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.js
More file actions
38 lines (34 loc) · 1.12 KB
/
logger.js
File metadata and controls
38 lines (34 loc) · 1.12 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
var userData = {
"internalIPs": [],
"externalIPs": {"ipv4": [], "ipv6": []},
"fingerprintHash": '',
"userAgent": navigator.userAgent
}
getIPs(function(ip){
//local IPs
if (ip.match(/^(192\.168\.|169\.254\.|10\.|172\.(1[6-9]|2\d|3[01]))/))
userData.internalIPs.push(ip);
//IPv6 addresses
else if (ip.match(/^[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7}$/))
userData.externalIPs["ipv6"].push(ip);
//assume the rest are public IPs
else
userData.externalIPs["ipv4"].push(ip);
});
new Fingerprint2().get(function(fingerprint, components){
// this will use all available fingerprinting sources
userData.fingerprintHash = fingerprint
// components is an array of all fingerprinting components used
});
var sendInfo = function(endpoint){
setTimeout(function(){
var xhr = new XMLHttpRequest();
xhr.open("POST", endpoint, true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
// send the collected data as JSON
xhr.send(JSON.stringify(userData));
xhr.onloadend = function () {
// done
}
}, 3000)
}