-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBlueCat Address Manager MultiPing Tool.user.js
89 lines (84 loc) · 3.52 KB
/
BlueCat Address Manager MultiPing Tool.user.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
// ==UserScript==
// @name BlueCat Address Manager MultiPing Tool
// @namespace *
// @description Tool to ping one or more IP(s) in the BlueCat Address Manager Network Addresses Tab
// @include */app*
// @version 2
// @grant none
// @author Marius Galm
// @copyright 2018, Marius Galm
// @license MIT
// @icon https://www.bluecatnetworks.com/wp-content/uploads/2018/03/cropped-bluecat-favicon-32x32.png
// @require https://rawgit.com/alfg/ping.js/master/dist/ping.min.js
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
// haha get the wordplay here
function doPing() {
var button = document.getElementById("doButton");
button.innerHTML = "<b>Pinging...</b><i> Results might take a while</i>";
// promise to sychronize async pinging operations
var promise = pingIP();
promise
.then(function(result) { console.log("Result: "+ result); })
.then(function(result) { var button = document.getElementById("doButton"); button.innerHTML = "<b>Ping Selected</b><i> Results are not reliable</i>"; });
}
// the real work
function pingIP () {
var deferred = $.Deferred();
var selected = document.getElementById("outerTable").getElementsByClassName("value-table-selected");
var ipLable = [];
var ipState = [];
var p = [];
var data = [];
var i = 0;
var nextStep = function() {
if (i < selected.length) {
p[i] = new Ping();
ipLable[i] = selected[i].getElementsByClassName("vo-label")[0];
var ip = trim(ipLable[i].innerText);
var ipLableText = ipLable[i].getElementsByTagName("a")[1];
p[i].ping("http://"+ip, function(err, data) {
// Also display error if err is returned.
if (err && data > 2000) {
console.log("error for IP "+ip+" was: "+err+" with data: "+data);
ipLableText.style.color= "green";
ipState[i] = "unreachable";
} else {
console.log("IP "+ip+" was reachable with data: "+data+" ("+err+")");
ipLableText.style.color = "red";
ipState[i] = "reachable";
}
});
i++;
setTimeout(nextStep, 500);
} else {
deferred.resolve();
}
};
nextStep();
return deferred.promise();
}
function resetButtonText() {
var button = document.getElementById("doButton");
button.innerHTML = "<b>Ping Selected</b>";
}
if (document.readyState === "interactive" ) {
// add the button only in addresses tab
var page = document.childNodes[2].nodeValue;
if (/ Page: IP4NetworkPage /.test(page)) {
var subtab = document.getElementsByClassName("TabPanelLabelActive")[0];
if (subtab.innerHTML.trim() == "Addresses" ) {
// Add button to first table
var topBar = document.getElementsByClassName('value-table-ToolBar')[0];
var comboBar = topBar.getElementsByClassName('combo-button-bar')[0];
var tBody = comboBar.getElementsByTagName('tbody')[0];
var tR = tBody.getElementsByTagName('tr')[0];
var w = tR.insertCell(-1);
w.innerHTML='<div class="separator"></div>';
var x = tR.insertCell(-1);
x.innerHTML='<span id="doButton"><b>Ping Selected</b><i> Results are not reliable</i></span>';
var lable = document.getElementById('doButton');
lable.addEventListener("click",() => { doPing(); },false);
}
}
}