Automated setup script (purchase hacknet servers & purchase and install private servers) – Bitburner

Automated setup script (purchase hacknet servers & purchase and install private servers) – Bitburner 1 - steamclue.com
Automated setup script (purchase hacknet servers & purchase and install private servers) – Bitburner 1 - steamclue.com

Actually got too lazy to keep manually running scripts to get all hacks up and running.
 
Then got even lazier having to purchase Private and Hacknet servers.
 
 
So I decided to write a combination of scripts that are triggered by one line of text, which then buys all 25 servers and runs in the background to keep buying hacknet nodes. Not perfect yet, but solid enough to share I think.
 
 

Intro

Really enjoying the game so far (maybe a bit too much).
 
Anyway, not much to say really but the idea behind the set of scripts was to not have to do much anymore. Or at least, allow me to focus on other mechanics of the game.
 
 
And sure, it saves me a bit of effort too, so maybe it’ll be useful to you as well.
 
 
First time writing a guide content, so expect issues haha. My Javascript skill level is average at best.
 
 
 

Main script

My idea was to have one script I could run upon reload of the game (for example after installing augmentations) which would setup my home server for hacking, keep running until I had enough money to buy a private server and get all hacks going on that new server. I just kept adding after that because it was fun to see it actually work. So now it purchases hacknet nodes too after all Private Server slots are filled.
 
 
Now the main script cannot run without other scripts, which are being called to perform the hacking, get root access or other stuff that needs to happen.
 
 
Four other scripts are included, see the other sections for the code bits on those.
 
 
====================
 
Main script (I called it “one_script_start.js”)
 
====================

 
 

/** @param {NS} ns **/export async function main(ns) {

 /*
 One-stop script that can do the following:
 1) Runs the base_server_setup.js script on home for early money, will check the RAM on home to determine thread count for each server
 2) Will wait until enough money is available to purchase a server with max RAM (1048576), cost ~57 billion each.
 NOTE: an alert will indicate you can buy the required software from the darkweb, do this to allow the script to continue.
 NOTE2: it cannot be automated early game as the functions to purchase from the darkweb require advanced upgrades
 3) Runs the adv_server_setup.js script on the newly purchased server
 4) Continues until all 25 servers are purchased.
 5) Will continue run in background to purchase hacknet nodes.
 
 Pre-requisites:
 - pen_hack_v1.js script (see below main script)
 - base_server_setup.js script (see below pen_hack_v1.js)
 - adv_server_setup.js script (see below base_server_setup.js)
 - back_hack_v1.js (see below adv_server_setup.js)
 
 Known issues:
 - Doesn't seem to hack all servers properly, which means some manual work still required; after all servers in scan range have root, the script will run without issue
 */ 

 var homeServer = "home";
 var availableCash = ns.getServerMoneyAvailable(homeServer);
 var serverCost = ns.getPurchasedServerCost('1048576');
 var homeMaxRam = ns.getServerMaxRam(homeServer);
 var homeUsedRam;
 var hostMaxRam;
 var hostUsedRam;
 var purchasedServerName;
 var ranBaseSetupOnce = 0;
 var nodeCost = ns.hacknet.getPurchaseNodeCost;
 var nodeMax = ns.hacknet.maxNumNodes();
 var serverMax = ns.getPurchasedServers();

 var basicServerList = [
 'iron-gym', 'harakiri-sushi', 'hong-fang-tea', 'joesguns', 'sigma-cosmetics', 'foodnstuff', 'n00dles'
 ]

 var advServerList = [
 'fulcrumtech', 'helios', 'vitalife', 'stormtech',
 'microdyne', 'titan-labs', 'applied-energetics', 'run4theh111z',
 'zb-def', 'taiyang-digital', 'nova-med', 'infocomm',
 'defcomm', 'univ-energy', 'solaris', 'icarus', 'zeus-med',
 'unitalife', 'omnia', 'deltaone',
 'global-pharm', 'snap-fitness', 'galactic-cyber', 'aerocorp',
 'aevum-police', 'millenium-fitness', 'lexo-corp', 'alpha-ent', 'rho-construction',
 'zb-institute', 'catalyst', 'summit-uni', 'rothman-uni', 'syscore', 'I.I.I.I',
 'avmnite-02h', 'comptek', 'crush-fitness', 'the-hub', 'netlink', 'johnson-ortho',
 'omega-net', 'silver-helix', 'phantasy', 'neo-net',
 'max-hardware', 'zer0', 'nectar-net',
 'iron-gym', 'harakiri-sushi', 'hong-fang-tea', 'joesguns', 'sigma-cosmetics', 'foodnstuff', 'n00dles'
 ]

 // Run the basic set-up script on Home and wait until all programs are bought
 while (ranBaseSetupOnce == 0) {

 ranBaseSetupOnce += 1;

 // Calculate threadcount based on available hosts's RAM, no decimals.
 var threadCount = homeMaxRam / (basicServerList.length * ns.getScriptRam("back_hack_v1.js"));
 threadCount.toPrecision(2);

 // For each server in the server list, run the hack script with calculated threadcount
 for (var i = 0; i < basicServerList.length; i++) {

 // Update RAM usage
 homeUsedRam = ns.getServerUsedRam(homeServer);

 // Check if root access exists, and if not hack the system first
 if (!ns.hasRootAccess(basicServerList))
ns.exec("pen_hack_v1.js", homeServer, 1, basicServerList);

// Ensure enough RAM exists by calculating script RAM usage (2.4GB * Threadcount)
if ((homeMaxRam - homeUsedRam) > (2.4 * threadCount))
ns.exec("back_hack_v1.js", homeServer, threadCount, basicServerList);
else
break;
}
}

// Check every 5 seconds if we have enough to purchase a server, run advanced setup right after
for (var j = 0; j < 25; j++) {

while (availableCash <= serverCost) {
await ns.sleep('5000');
availableCash = ns.getServerMoneyAvailable(homeServer);
if (availableCash > 6000000000 && !ns.fileExists('Formulas.exe', homeServer))
ns.tprint('You have enough money to purchase the darkweb programs');
}

// once we have enough cash, purchase a server with MAX ram amount and name it
if (availableCash > serverCost && serverMax.length != 24) {

ns.tprint('Starting server purchase pass: ' + j);

purchasedServerName = 'fws-vpn-' + j;

ns.purchaseServer(purchasedServerName, '1048576');

hostMaxRam = ns.getServerMaxRam(purchasedServerName);

// Calculate threadcount based on available hosts's RAM, no decimals.
threadCount = hostMaxRam / (advServerList.length * ns.getScriptRam("back_hack_v1.js"));
threadCount.toPrecision(2);

// Copy the script to the host server if it isn't there yet
if (!ns.fileExists('back_hack_v1.js', purchasedServerName))
await ns.scp("back_hack_v1.js", homeServer, purchasedServerName);

ns.tprint('Server purchased: ' + purchasedServerName);

// For each server in the server list, run the hack script with calculated threadcount
for (var k = 0; k < advServerList.length; k++) {

// Update RAM usage
hostUsedRam = ns.getServerUsedRam(purchasedServerName);

// Check if root access exists, and if not hack the system first
if (ns.hasRootAccess(advServerList[k]) == false)
ns.exec("pen_hack_v1.js", homeServer, 1, advServerList[k]);

await ns.sleep('100');

// Ensure enough RAM exists by calculating script RAM usage (2.4GB * Threadcount)
if ((hostMaxRam - hostUsedRam) > (2.4 * threadCount))
ns.exec("back_hack_v1.js", purchasedServerName, threadCount, advServerList[k]);
else
break;
}
}
}

// Start the hacknet node passes
while (ns.hacknet.numNodes() < nodeMax) {

nodeCost = ns.hacknet.getPurchaseNodeCost();

// Purchase the nodes when we have enough money to do so
if (availableCash > (nodeCost + 250000000)) {

var purchaseIndex = ns.hacknet.purchaseNode();
ns.hacknet.upgradeLevel(purchaseIndex, 199);
ns.hacknet.upgradeRam(purchaseIndex, 6);
ns.hacknet.upgradeCore(purchaseIndex, 15);

ns.tprint('Hacknet node purchased, index[' + purchaseIndex + ']');
}

// wait a few seconds before we have them all
await ns.sleep('5000');
}
}[/code]

 
 
 

Penetration hack

====================
 
Penetration hack script (pen_hack_v1.js)
 
This script is used to run the actual hacks on the systems.
 
====================

 
 

/** @param {NS} ns **/export async function main(ns) {

 var target = ns.args[0];
 
 // Brute force open the ports
 if (ns.fileExists("BruteSSH.exe"))
 ns.brutessh(target);
 
 // Open the FTP port
 if (ns.fileExists("ftpcrack.exe"))
 ns.ftpcrack(target);
 
 // Open the SMTP port
 if (ns.fileExists('RelaySMTP.exe'))
 ns.relaysmtp(target);

 // Open the SMTP port
 if (ns.fileExists('HTTPWorm.exe'))
 ns.httpworm(target);

 // Open the SMTP port
 if (ns.fileExists('SQLInject.exe'))
 ns.sqlinject(target);

 // Nuke the machine if we don't have access yet
 ns.nuke(target);

 // Install the backdoor
 // ns.installBackdoor(target);
}

 
 
 

Basic Server Setup script (scan-level 0)

====================
 
Base Server script to thread into scan level 0 servers (base_server_setup.js)
 
(to be used on home until you get the first server running and have all software)
 
====================

 
 

/** @param {NS} ns **/export async function main(ns) {

 // Arguments provided by network_crawler script
 var hostServer = ns.args[0];
 var hostMaxRam = ns.getServerMaxRam(hostServer);
 var hostUsedRam;

 var serverList = ['iron-gym', 'harakiri-sushi', 'hong-fang-tea', 'joesguns', 'sigma-cosmetics', 'foodnstuff', 'n00dles'];

 // Calculate threadcount based on available hosts's RAM
 var threadCount = hostMaxRam / (serverList.length * ns.getScriptRam("back_hack_v1.js"));

 // No decimals!
 threadCount.toPrecision(2);

 // Copy the script to the host server if it isn't there yet
 if (!ns.fileExists('back_hack_v1.js', hostServer))
 await ns.scp("back_hack_v1.js", "home", hostServer);

 // For each server in the server list, run the hack script with calculated threadcount
 for (var i = 0; i < serverList.length; i++) {

 // Update RAM usage
 hostUsedRam = ns.getServerUsedRam(hostServer);
 
 // Check if root access exists, and if not hack the system first
 if (!ns.hasRootAccess(serverList))
ns.exec("pen_hack_v1.js", "home", 1, serverList);

// Ensure enough RAM exists by calculating script RAM usage (2.4GB * Threadcount)
if ((hostMaxRam - hostUsedRam) > (2.4 * threadCount))
ns.exec("back_hack_v1.js", hostServer, threadCount, serverList);
else
break;
}
}[/code]

 
 
 

Advanced Server Setup script (scan-level 10)

====================
 
Advanced Server script to thread into scan level 10 servers (adv_server_setup.js)
 
====================

 
 

/** @param {NS} ns **/export async function main(ns) {

 // Arguments provided by network_crawler script
 var hostServer = ns.args[0];
 var hostMaxRam = ns.getServerMaxRam(hostServer);
 var hostUsedRam;

 var serverList = ['zb-def', 'taiyang-digital', 'nova-med', 'infocomm',
 'defcomm', 'univ-energy', 'solaris', 'icarus', 'zeus-med',
 'unitalife', 'omnia', 'deltaone',
 'global-pharm', 'snap-fitness', 'galactic-cyber', 'aerocorp',
 'aevum-police', 'millenium-fitness', 'lexo-corp', 'alpha-ent', 'rho-construction',
 'zb-institute', 'catalyst', 'summit-uni', 'rothman-uni', 'syscore',
 'comptek', 'crush-fitness', 'the-hub', 'netlink', 'johnson-ortho',
 'omega-net', 'silver-helix', 'phantasy', 'neo-net',
 'max-hardware', 'zer0', 'CSEC', 'nectar-net',
 'iron-gym', 'harakiri-sushi', 'hong-fang-tea', 'joesguns', 'sigma-cosmetics', 'foodnstuff', 'n00dles'];

 // Calculate threadcount based on available hosts's RAM
 var threadCount = hostMaxRam / (serverList.length * ns.getScriptRam("back_hack_v1.js"));

 // No decimals!
 threadCount.toPrecision(2);

 // Copy the script to the host server if it isn't there yet
 if (!ns.fileExists('back_hack_v1.js', hostServer))
 await ns.scp("back_hack_v1.js", "home", hostServer);

 // For each server in the server list, run the hack script with calculated threadcount
 for (var i = 0; i < serverList.length; i++) {

 // Update RAM usage
 hostUsedRam = ns.getServerUsedRam(hostServer);
 
 // Check if root access exists, and if not hack the system first
 if (ns.hasRootAccess(serverList) == false)
ns.exec("pen_hack_v1.js", "home", 1, serverList);

// Ensure enough RAM exists by calculating script RAM usage (2.4GB * Threadcount)
if ((hostMaxRam - hostUsedRam) > (2.4 * threadCount))
ns.exec("back_hack_v1.js", hostServer, threadCount, serverList);
else
break;
}
}[/code]

 
 
 

Cash scraping script

Everyone probably has one of these by now, but in case you needed a basic hacking script (which I call in the main script anyway) then please see it below:
 
 
====================
 
Actual hacking script which generates the dosh; can always be tweaked but below works fine for me.
 
Named the script back_hack_v1.js
 
====================

 
 

/** @param {NS} ns **/export async function main(ns) {

 var target = ns.args[0];
 var cashTresh = ns.getServerMaxMoney(target) * 0.75;
 var secuTresh = ns.getServerMinSecurityLevel(target) + 5;

 // Main extraction loop
 while (true) {
 if (ns.getServerSecurityLevel(target) > secuTresh) {
 await ns.weaken(target);
 } else if (ns.getServerMoneyAvailable(target) > cashTresh) {
 await ns.hack(target);
 } else {
 await ns.grow(target);
 }
 }
}

 
 
 

Known issues

1) NUKE.exe doesn’t always complete on all servers, even when all software is available to ensure a hack
 
The penetration hack script doesn’t always seem to execute properly, have not found out why yet. Built in a timer to see if it was executing too fast, but so far it still occurs sometimes. What happens is of all the servers mentioned, 80% gets hacked and the rest somehow doesn’t want to. Manually hacking them and re-running the script works fine as a work-around.
 
 
 

Usage Notes

1) The main script requires no arguments to run.
 
 
2) Possible spoiler (it took me a while to find out haha): A terminal message will be provided when you have enough money to buy all software from the darkweb
 
 
3) If somehow you mess up with a script (as I do occasionally) and have to kill all scripts, you can simply re-run the main script again. The naming convention of purchased servers might be messed up when the script crashes before all servers are purchased, other than that it still creates them and installs them.
 
 

Written by Sjnuffel

 
 
Here we come to an end for the Automated setup script (purchase hacknet servers & purchase and install private servers) – Bitburner guide. I hope this guide has helped you with your gameplay. If you have something to add to this guide or believe we forgot some information to add, please let us know via comment! We check each comment manually by approving them!
 


Be the first to comment

Leave a Reply

Your email address will not be published.


*