Created
May 20, 2022 06:30
-
-
Save heathkit/0a1dabf162dd10236f62e75024e3452f to your computer and use it in GitHub Desktop.
scan.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let servers = []; | |
/** @param {NS} ns */ | |
export async function main(ns) { | |
ns.tail() | |
ns.disableLog("ALL") | |
let previousHost = ns.args[0]; | |
ns.printf("Previous host: %s", previousHost); | |
let currentHost = ns.getHostname(); | |
await scan(ns, currentHost); | |
servers = [...new Set(servers)] | |
servers.sort((a, b) => { | |
return ns.getServerMaxMoney(a) - ns.getServerMaxMoney(b) | |
}) | |
ns.write("servers.txt", JSON.stringify(servers), "w") | |
} | |
/** @param {NS} ns */ | |
async function scan(ns, currentHost, previousHost) { | |
let hosts = ns.scan(currentHost); | |
for (let host of hosts) { | |
if (host === previousHost) continue; | |
if (host === "darkweb") continue; | |
if (host.includes("pserv-")) continue; | |
servers.push(host); | |
ns.print(`${host} (${previousHost})`) | |
if (!ns.hasRootAccess(host) && (ns.getServerRequiredHackingLevel(host) <= ns.getHackingLevel())) { | |
try { | |
await ns.brutessh(host); | |
await ns.ftpcrack(host); | |
await ns.relaysmtp(host); | |
await ns.httpworm(host); | |
await ns.sqlinject(host); | |
} catch { } | |
try { | |
await ns.nuke(host); | |
ns.print(`NUKE: ${host}`) | |
ns.toast(`NUKE: ${host}`) | |
} catch { | |
ns.print(`FAIL: ${host}`) | |
} | |
} | |
await scan(ns, host, currentHost) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment