Bitburner – Automatic setup script – Buy hacknet servers and Install private servers

Bitburner – Automatic setup script – Buy hacknet servers and Install private servers 1 - steamlists.com
Bitburner – Automatic setup script – Buy hacknet servers and Install private servers 1 - steamlists.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

 
 
This is all about Bitburner – Automatic setup script – Buy hacknet servers and Install private servers; I hope you enjoy reading the Guide! If you feel like we should add more information or we forget/mistake, please let us know via commenting below, and thanks! See you soon!
 
 


11 Comments

  1. For what ever reason, even with the fix in place (adding [i] to server list

    Lines 64 through 80 of main file:

    // For each server in the server list, run the hack script with calculated threadcount
    for (var i = 0; i (2.4 * threadCount))
    ns.exec(“back_hack_v1.js”, homeServer, threadCount, basicServerList[i]);
    else
    break;
    }
    }

    I still only get 6 out of the 7 servers… in other words, with the base list, I never get n00dles.

    • Wow… It did njot copy right at all… So I will make it easier for all.

      Main file, line 71, add “[i]” to basicServerList so it looks like basicServerList[i]
      Do the same on lines 72 and 76

      • hey thanks for solving problem, it work
        and about n00dles prolem you just add more behind it like n00dles,NON
        at line basic 37
        adv 52

        it will warn you about [what the F* is NON](ignored it) and n00dles will active but for some reason lost sight of run.js

  2. Okay, for those of you really scratching your head, the variable needs to be attached to serverlist. I was able to get my script to run fine after these modifications:

    // Copy the script to the host server if it isn’t there yet
    if (!ns.fileExists(‘basic_hack.js’, hostServer))
    await ns.scp(“basic_hack.js”, “home”, hostServer);

    // For each server in the server list, run the hack script with calculated threadcount
    for (var i = 0; i (2.4 * threadCount))
    ns.exec(“basic_hack.js”, hostServer, threadCount, serverList[i]);
    else
    break;
    }
    }

  3. The Indexes are missing …

    // 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 (2.4 * threadCount))
    ns.exec(“back_hack_v1.js”, homeServer, threadCount, basicServerList[i]);
    else
    break;
    }
    }

    • I have been working on this, and I can’t figure out why I keep getting a syntax error…

      // For each server in the server list, run the hack script with calculated threadcount
      for (var i = 0; i (2.4 * threadCount)) {
      // 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(“breach_basic.js”, “home”, 1, serverLis[i]);

      // Ensure enough RAM exists by calculating script RAM usage (2.4GB * Threadcount)
      if ((hostMaxRam – hostUsedRam) > (2.4 * threadCount))
      ns.exec(“basic_hack.js”, hostServer, threadCount, serverList[i]);
      else
      break;
      }
      }

  4. Try this…

    // For each server in the server list, run the hack script with calculated threadcount
    for (var i = 0; i (2.4 * threadCount))
    ns.exec(“back_hack_v1.js”, homeServer, threadCount, serv);
    else
    break;
    }
    }

  5. Trying to be super lazy here and I’m no coder…

    Having trouble getting the thing to run in the first place. It keeps giving me “Invalid hostname or IP” which doesn’t make any sense since everything seems to be spelled correctly, unless it’s not pulling individual elements from the array and is instead trying to input the entire array as a single argument.

    • Yeah, exact same issue here, according to Bitburner the issue is in L71 of the main script. It does seem like it’s trying to put the entire array in, instead of a single IP/Hostname at a time.

      Full Error:
      RUNTIME ERROR:
      [email protected]

      hasRootAccess: Invalid hostname or IP: iron-gym,harakiri-sushi,hong-fang-tea,joesguns,sigma-cosmetics,foodnstuff,n00dles

      Stack:
      auto-hack.js:[email protected]

    • under “var basicServerList” change the brackets to parantheses and the apostrophes to quotations, i did the same for advServerList just in case

Leave a Reply

Your email address will not be published.


*