This repository has been archived by the owner on Nov 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
95 lines (72 loc) · 2.23 KB
/
background.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
90
91
92
93
94
95
var lastMacClient = getMacClient();
setInterval(function () {
var newListArray = getMacClient();
var newClient = getNewClient(newListArray);
lastMacClient = newListArray;
if (newClient[0] == undefined) {
return;
}
for (var i in newClient) {
var notific = new window.Notification('Новый клиет Wi-Fi', {
icon:"favicon.png",
body:"Имя: " + newClient[i][1] + "\nMAC: " + newClient[i][0]
})
}
}, 2000);
function getMacClient () {
var listClient = [];
var XMLRequest = new XMLHttpRequest();
XMLRequest.open('POST', 'http://192.168.1.1/ci', false, 'admin', '1234');
XMLRequest.setRequestHeader('Content-Type', 'application/xml');
XMLRequest.send('<?xml version="1.0" encoding="UTF-8"?><packet><request id="client"><command name="show associations" /></request><request id="name"><command name="show ip arp"><alive>alive</alive></command></request></packet>');
var XMLdom = XMLRequest.responseXML;
var clients = XMLdom.getElementById('client').getElementsByTagName('station');
var nameClients = XMLdom.getElementById('name').getElementsByTagName('arp');
var countClient = clients.length;
for (var i = 0; i < countClient; i++) {
var mac = clients[i].getElementsByTagName('mac')[0].innerHTML;
var name = getNameUser(mac, nameClients);
listClient[mac] = name;
}
return listClient;
}
function getNameUser (mac, nameClients) {
var countNameClient = nameClients.length;
for (var i = 0; i < countNameClient; i++) {
if (nameClients[i].getElementsByTagName('mac')[0].innerHTML === mac && nameClients[i].getElementsByTagName('name').length != 0) {
return nameClients[i].getElementsByTagName('name')[0].innerHTML;
}
}
return '???';
}
function getCountIndexArray (newArray, oldArray) {
var hash = [];
for (var i in oldArray) {
if (hash[i] == undefined) {
hash[i] = 1;
}
else {
hash[i] += 1;
}
}
for (var i in newArray) {
if (hash[i] == undefined) {
hash[i] = 1;
}
else {
hash[i] += 1;
}
}
return hash;
}
function getNewClient (newArray) {
var newClient = [];
var hash = getCountIndexArray(newArray, lastMacClient);
for (var mac in hash) {
var count = hash[mac];
if (count == 1 && newArray[mac] != undefined) {
newClient.push([mac, newArray[mac]]);
}
}
return newClient;
}