Bitburner Script + Nuke Available Servers Automation

Bitburner Script + Nuke Available Servers Automation 1 -
Bitburner Script + Nuke Available Servers Automation 1 -

For those who are looking for something useful out here. I hope you will not blindly copy/paste it in your game but will find out few new ideas for structuring your code.
Also I can see several rooms for improvements:

  • Create supervisor process that will watch for new available nodes and nuke them for you, so you need to execute something like `run nuke-all-supervisor.js` only once per installing augments.
  • Another room for improvement is installing backdoor. It needs you to progress in the game a bit though, in order to unlock required API.




 run nuke-all.js 

Nukes all the servers you have meet hacking level. As simple as it looks like. No further attention required. Branding image contains my very first step after installing augments.

Memory consumption

As you can see below, memory consumption for this script is below 8G, which mean you can use it at early game. (I only now have recognized that getPurchasedServers function takes half of RAM and it doesn’t really required, so you can improve memory consumption for your needs).

[home ~/]> mem nuke-all.js 
This script requires 4.75GB of RAM to run for 1 thread(s)
 2.25GB | getPurchasedServers (fn)
 1.60GB | baseCost (misc)
200.00MB | scan (fn)
100.00MB | getServerRequiredHackingLevel (fn)
100.00MB | getServerNumPortsRequired (fn)
100.00MB | fileExists (fn)
 50.00MB | hasRootAccess (fn)
 50.00MB | getHackingLevel (fn)
 50.00MB | nuke (fn)
 50.00MB | brutessh (fn)
 50.00MB | ftpcrack (fn)
 50.00MB | relaysmtp (fn)
 50.00MB | httpworm (fn)
 50.00MB | sqlinject (fn)




nuke-all.js – Executable script uses library functions to clarify and simplify behavior.

import { acquireRootAccess, buildNetwork, networkToServerList } from 'utils'

/** @param {NS} ns **/export async function main(ns) {
 const network = buildNetwork(ns)
 const networkList = networkToServerList(network)
 const notNuked = networkList.filter((server) => !ns.hasRootAccess(server))
 for (const host of notNuked) {
 acquireRootAccess(ns, host)

 ns.toast(`${ns.getScriptName()} done`)

utils.js – Set of utility/library functions

 * Returns list of callables you can use to open ports on specified server.
 * @param {NS} ns
 * @returns {Array.<(server: string): void>} 
 */export function getAvailableMethods(ns) {
 const methods = []
 for (const [method, file] of [
 [ns.brutessh, 'BruteSSH.exe'],
 [ns.ftpcrack, 'FTPCrack.exe'],
 [ns.relaysmtp, 'relaySMTP.exe'],
 [ns.httpworm, 'HTTPWorm.exe'],
 [ns.sqlinject, 'SQLInject.exe']
 ]) {
 if (ns.fileExists(file)) {
 return methods

 * Try to acquire Root access to the target server.
 * @param {NS} ns
 * @param {string} target Server name to get Root access to.
 * @returns {boolean} Was attempt successful or not.
 */export function acquireRootAccess(ns, target) {
 if (!ns.hasRootAccess(target)) {
 if (ns.getHackingLevel() < ns.getServerRequiredHackingLevel(target)) {
 ns.print(`ERROR: Not enough hacking level for ${target}`)
 return false
 const methods = getAvailableMethods(ns);
 if (methods.length < ns.getServerNumPortsRequired(target)) {
 ns.print(`ERROR: Not enough breaking methods for ${target}`)
 return false
 for (const method of methods) {
 return true

 * Simple directed graph representation of a network, which consists of
 * it's name and list of child nodes.
 * @typedef {{name: string, children: NetworkNode[]}} NetworkNode
 * Returns network representation in form of directed graph using DFS.
 * The most common case is that you do not care about network nodes you can 
 * not nuke right now. That is why this function only returns nodes for 
 * which you have meet hacking level.
 * @param {NS} ns
 * @param {string} name Name of the network node/server we are working with.
 * @param {string[]} used List of nodes we have already processed.
 * @returns {NetworkNode} Directed graph
 */export function buildNetwork(ns, name = 'home', used = []) {
 const node = { name: name, children: [] }
 const serverList = ns.getPurchasedServers()
 for (const child of ns.scan( - []  {
 if (ns.getServerRequiredHackingLevel(child) <= ns.getHackingLevel() && 
 !used.includes(child) && !serverList.includes(child)
 ) {
 node.children.push(buildNetwork(ns, child, used))
 return node

 * It is not strictly required to works with network in form of a graph. 
 * Sometimes we just have to know what nodes are present. This is what 
 * this function is for: to convert data structure format from directed 
 * graph to plain list of network's nodes.
 * @param {NetworkNode} node
 * @returns {string[]} List of all servers in the network.
 */export function networkToServerList(node) {
 const list = [ - [] ]
 if (node.children.length) {
 for (const child of node.children) {
 return list



Written by koutoftimer

Hope you enjoy the post for Bitburner Script + Nuke Available Servers Automation, If you think we should update the post or something is wrong please let us know via comment and we will fix it how fast as possible! Thank you and have a great day!

Be the first to comment

Leave a Reply

Your email address will not be published.