-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathmyscan.js
More file actions
49 lines (44 loc) · 1.31 KB
/
Copy pathmyscan.js
File metadata and controls
49 lines (44 loc) · 1.31 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
/** @param {NS} ns **/
export async function main(ns) {
ns.disableLog('ALL');
var servers = RecursiveScan(ns);
var target = ns.args[0];
for (const server of servers) {
if (target != null) {
if (server.name.search(target) != -1) {
ns.tprint(server.route);
// Exploit to enter and run the command on the terminal, must be on the terminal tab to work
try {
const terminalInput = eval('document').getElementById("terminal-input");
terminalInput.value = server.route;
const handler = Object.keys(terminalInput)[1];
terminalInput[handler].onChange({ target: terminalInput });
terminalInput[handler].onKeyDown({ key: 'Enter', preventDefault: () => null });
}
catch { }
}
}
else
ns.tprint(server.route);
}
ns.tprint('Total servers explored: ' + servers.length);
}
function RecursiveScan(ns, root, found, route) {
if (route == null) route = '';
else route = route + ';connect ' + root;
if (found == null) found = new Array();
if (root == null) {
root = 'home';
route = 'connect home';
}
if (found.find(p => p == root) == undefined) {
var entry = {};
entry.name = root;
entry.route = route;
found.push(entry);
for (const server of ns.scan(root))
if (found.find(p => p.name == server) == undefined)
RecursiveScan(ns, server, found, route);
}
return found;
}