Skip to content
Riot Bits

Riot Bits

  • Home
  • News
  • Guides
  • Video Guides
  • Patch Notes
  • Report Abuse
  • Toggle search form
Bitburner

Bitburner – Nuke Available Servers Automation

Posted on 01/20/2022 By koutoftimer No Comments on Bitburner – Nuke Available Servers Automation
  • Title: Bitburner
  • Release Date:
  • Developer:
  • Publisher:
Information about Bitburner is still incomplete. Please help us fill the details of the game using this contact form.

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 a 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 the required API.

Usage

run nuke-all.js

Nukes all the servers you have to meet hacking level. As simple as it looks. No further attention is 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 means you can use it at early game. I only now have recognized that the getPurchasedServers function takes half of RAM and it doesn’t really require it, 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)

Scripts

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)) {
			methods.push(method)
		}
	}
	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) {
			method(target)
		}
		ns.nuke(target)
	}
	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 = []) {
	used.push(name)
	const node = { name: name, children: [] }
	const serverList = ns.getPurchasedServers()
	for (const child of ns.scan(node.name)) {
		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 = [node.name]
	if (node.children.length) {
		for (const child of node.children) {
			list.push(...networkToServerList(child))
		}
	}
	return list
}

That's everything we are sharing today for this Bitburner guide. This guide was originally created and written by koutoftimer. In case we fail to update this guide, you can find the latest update by following this link.

If you believe that any of the content on this site violates your rights, including your intellectual property rights, please contact us immediately using our contact form.
Guides Tags:Bitburner

Post navigation

Previous Post: Moonlighter – General Info and Secret Rooms Guide
Next Post: Labyrinthine – Level 5 Map + Collectibles Locations Guide

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Title: Bitburner
  • Release Date:
  • Developer:
  • Publisher:
Information about Bitburner is still incomplete. Please help us fill the details of the game using this contact form.

Disclaimer

All content cited is derived from their respective sources. If you think we have used your content without permission, make sure to reach us and we will be taking it seriously.
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of Service

Copyright © 2025 Riot Bits.

Powered by PressBook News WordPress theme