-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworm_v1.js
38 lines (34 loc) · 1.07 KB
/
worm_v1.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
/** @param {NS} ns */
/**
* copies itself to each nearby server
* attempts to hack any server it is on
* copies itself to each nearby server again
* PARAMS: none
*
* --NOT FUNCTIONAL--
*/
export async function main(ns) {
let visited = ns.args;
const host = ns.getHostname();
const servers = ns.scan(host);
visited.push(...servers);
// copy script on each server in the list
for (let server of servers) {
ns.scp(script, server);
ns.tprint("copied ", script, " to ", server);
// find out how many threads we can run
ns.killall(server)
let serverRam = ns.getServerMaxRam(server);
let threads = Math.floor(serverRam / scriptRam);
// quick check that we can actually run scripts on server
if (ns.hasRootAccess(server)) {
// finally, execute the script with max threads
let maxMoney = ns.getServerMaxMoney(server);
let minSecurity = ns.getServerMinSecurityLevel(server);
ns.exec(script, server, threads, target, maxMoney, minSecurity);
ns.tprint(threads, " threads were deployed to ", server);
} else {
ns.tprint("NO ROOT ACCESS ON: ", server)
}
}
}