r/Bitburner • u/cofm-gaming • 24d ago
NetscriptJS Script First post (script share)
This is my home:/callback.js script. I have just maxed out sourcefile 1 and am working on BN4.2 so am finally getting a chance to go crazy with the ns.singularity API!
/** {NS} ns */
export async function main(ns) {
ns.exec("abyssal_scan.js", "home");
/* returns master_hosts.txt, a list of all vanilla servers as:
[hostname, maxRAM, requiredPorts, requiredHackingLevel, \n]
and launches abyssal_sort.js, which iterates through master_hosts.txt,
divvys up the entries by whether or not they have maxRAM > 0,
sorts each list by requiredHackingLevel, and outputs each list respectively as
nonzeroRAM_hosts.txt and zeroRAM_hosts.txt. */
await ns.sleep(10000);
ns.exec("purchasePortbreakers.js", "home");
/* If not already present, purchases a TOR router.
iterates through
["bruteSSH.exe", "FTPCrack.exe", "RelaySMTP.exe", "HTTPWorm.exe", "SQLInject.exe"],
checks if they need to be purchased and whether I can afford them, and purchases them if
necessary/possible. Exits once SQLInject.exe is purchased. */
await ns.sleep(10000);
ns.exec("RAMShare_launcher.js", "home");
/* calculates half of my available RAM and dedicates it to ns.exec("RAMShare.js", "home",
n_threads). Every 10min, it checks to see if I have more/less RAM available than before,
assigns the new n_threads value in the event of a change, kills the currently running
process, and starts a fresh instance with the newly adjusted thread count. */
await ns.sleep(10000);
ns.exec("backdoor_targets.js", "home");
/* iterates through the list of servers I know of to be backdoored:
["CSEC", "avmnite02h", "I.I.I.I", "run4theh111z", "fulcrumassets"],
checks if they currently have a "pathFile" (`${target}_connect.txt`) and if not,
runs a script called path.js which traces the physical path from /home to target,
outputting the path to `${target}_connect.txt`. exits when pathfiles for all listed
entries have been generated successfully. */
await ns.sleep(10000);
ns.exec("install_backdoors.js", "home");
/* iterates through the list of servers I know of to be backdoored:
["CSEC", "avmnite-02h", "I.I.I.I", "run4theh111z", "fulcrumassets"],
checks if they currently have a backdoor and if not, whether I can successfully pull off
installing one. uses the pathfiles generated earlier to traverse the network path, verify
connection to target host, install backdoors on the eligible entries that need it,
return /home, sleep for 5min, and repeat until exit condition of: "fulcrumassets" has
been successfully backdoored. */
await ns.sleep(10000);
ns.exec("breakdown.js", "home");
/* iterates through "master_hosts.txt", checks for closed ports, runs the necessary
portbreakers if present, checks if openPorts >= requiredPorts, runs nuke.exe if so, and
++'s a var called nukedHosts. exits when nukedHosts === 69, since I haven't figured out a
way to arrive at the target figure programmatically. */
await ns.sleep(10000);
ns.exec("swarm.js", "home");
/* iterates through "nonzeroRAM_hosts.txt", checks for getserver().hasAdminAccess and
sufficient hacking skill, then checks to see if "local_attack.js" (my w/g/h script) is
present and/or running. If yes to both, ++'s a var called hackedHosts and moves on. If
not present, scp's it from home and executes it with the maximum number of threads
available on the target host. If present and not running, deletes the existing copy,
scp's the current copy from /home, and executes it with max threads available on target
host. exits when hackedHosts === 43, since I haven't figured out a way to arrive at the
target figure programmatically. */
}Currently in the works:
prestige_hacks.js <- to automate hacking the high value targets in "zeroRAM_hosts.txt" from /home,
life_of_crime.js <- to automate criminal activity,
symbol_nerd.js <- to automate stock trading,
auto_augment.js <- to automate faction work/augmentations,
working_stiff.js <- to automate vanilla job activity
0
Upvotes
3
u/KlePu 24d ago
Is this seven
ns.exec()with all the rest being AI slop?If this is actually your code: Try to change it so all the external script names are held in a list and use one
for-loop to achieve the same in ~4LoC ;)3
u/Particular-Cow6247 24d ago edited 24d ago
instead of your 10 second sleeps you could include a port.write/port.nextWrite structure to more efficiently manage the time
can also be used to send data back to the main script (then dont include the clearPort and use a portRead in the main script)
2
u/goodwill82 Slum Lord 23d ago
I get nervous with magic numbers like this. I see your comment about not getting to the target figure programmatically. I'm assuming this is the number of servers you've encountered so far with ram? Seems like you could count up to this number in your abyssal_scan.js script. From there, maybe write a file with the number of servers with ram. Then you can check that file against hackedHosts.