Files
bitburner-src/markdown/bitburner.ns.md

20 KiB
Raw Blame History

Home > bitburner > NS

NS interface

Collection of all functions passed to scripts

Signature:

export interface NS 

Remarks

Basic usage example:

export async function main(ns) {
 // Basic ns functions can be accessed on the ns object
 ns.getHostname();
 // Some related functions are gathered under a sub-property of the ns object
 ns.stock.getPrice();
 // Most functions that return a promise need to be awaited.
 await ns.hack('n00dles');
}

Properties

Property

Modifiers

Type

Description

args

readonly

ScriptArg[]

Arguments passed into the script.

These arguments can be accessed as a normal array by using the [] operator (args[0], args[1], etc...). Arguments can be string, number, or boolean. Use args.length to get the number of arguments that were passed into a script.

bladeburner

readonly

Bladeburner

Namespace for Bladeburner functions. Contains spoilers.

cloud

readonly

Cloud

Namespace for cloud functions.

codingcontract

readonly

CodingContract

Namespace for coding contract functions.

corporation

readonly

Corporation

Namespace for corporation functions. Contains spoilers.

dnet

readonly

Darknet

Namespace for darknet functions. Contains spoilers.

enums

NSEnums

format

readonly

Format

Namespace for formatting functions.

formulas

readonly

Formulas

Namespace for formulas functions.

gang

readonly

Gang

Namespace for gang functions. Contains spoilers.

go

readonly

Go

Namespace for Go functions.

grafting

readonly

Grafting

Namespace for grafting functions. Contains spoilers.

hacknet

readonly

Hacknet

Namespace for hacknet functions. Some of this API contains spoilers.

heart

readonly

{ break(): number; }

infiltration

readonly

Infiltration

Namespace for infiltration functions.

pid

readonly

number

The current script's PID

singularity

readonly

Singularity

Namespace for singularity functions. Contains spoilers.

sleeve

readonly

Sleeve

Namespace for sleeve functions. Contains spoilers.

stanek

readonly

Stanek

Namespace for Stanek functions. Contains spoilers.

stock

readonly

Stock

Namespace for stock functions.

ui

readonly

UserInterface

Namespace for user interface functions.

Methods

Method

Description

alert(args)

Open up a message box.

asleep(millis)

Suspends the script for n milliseconds. Doesn't block with concurrent calls.

atExit(f, id)

Add a callback to be executed when the script dies.

brutessh(host)

Runs BruteSSH.exe on a server.

clear(handle)

Clear data from a file.

clearLog()

Clears the scripts logs.

clearPort(portNumber)

Clear data from a port.

disableLog(fn)

Disables logging for the given NS function.

dnsLookup(host)

Given a hostname, returns its IP address; or given an IP address, returns its hostname.

dynamicImport(path)

Dynamically import a script. Only scripts located on the same server can be imported. A dynamic import will not adjust RAM usage. This must be done manually with ramOverride.

enableLog(fn)

Enables logging for the given NS function.

exec(script, host, threadOrOptions, args)

Start another script on any server.

exit()

Terminates the current script immediately.

fileExists(filename, host)

Check if a file exists.

flags(schema)

Parse command line flags.

ftpcrack(host)

Runs FTPCrack.exe on a server.

getBitNodeMultipliers(n, lvl)

Get the current BitNode multipliers.

getFavorToDonate()

Returns the amount of Faction favor required to be able to donate to a faction.

getFileMetadata(filename)

Get the metadata of a file.

getFunctionRamCost(name)

Get the ram cost of a netscript function.

getGrowTime(host)

Get the execution time of a grow() call.

getHackingLevel()

Returns the players current hacking level.

getHackingMultipliers()

Get hacking related multipliers.

getHacknetMultipliers()

Get hacknet related multipliers.

getHackTime(host)

Get the execution time of a hack() call.

getHostname()

Returns a string with the hostname of the server that the script is running on.

getIP()

Returns a string with the IP address of the server that the script is running on.

getMoneySources()

Get information about the sources of income for this run.

getPlayer()

Get information about the player.

getPortHandle(portNumber)

Get all data on a port.

getRecentScripts()

Get an array of recently killed scripts across all servers.

getResetInfo()

Get information about resets.

getRunningScript(filename, host, args)

Get general info about a running script.

getScriptExpGain(script, host, args)

Get the exp gain of a script.

getScriptIncome(script, host, args)

Get the income of a script.

getScriptLogs(fn, host, args)

Get all the logs of a script.

getScriptName()

Returns the current script name.

getScriptRam(script, host)

Get the ram cost of a script.

getServer(host)

Returns data of a server.

If the server is a darknet server and has recently gone offline, it will return a dummy server object with isOnline: false.

getServerBaseSecurityLevel(host)

Get the base security level of a server.

getServerGrowth(host)

Get a server growth parameter.

getServerMaxMoney(host)

Get the maximum money available on a server.

getServerMaxRam(host)

Get the maximum amount of RAM on a server.

getServerMinSecurityLevel(host)

Returns the minimum security level of the target server.

getServerMoneyAvailable(host)

Get money available on a server.

getServerNumPortsRequired(host)

Returns the number of open ports required to successfully run NUKE.exe on the specified server.

getServerRequiredHackingLevel(host)

Returns the required hacking level of the target server.

getServerSecurityLevel(host)

Get server security level.

getServerUsedRam(host)

Get the used RAM on a server. This includes ram used by running scripts as well as blocked ram on darknet servers.

getSharePower()

Share power has a multiplicative effect on rep/second while doing hacking work for a faction. If you do non-hacking work, share power still increases the reputation gain rate, but the effect is non-linear.

Share power increases incrementally for every thread of share running on your server network, but at a sharply decreasing rate.

getTotalScriptExpGain()

Get the exp gain of all scripts.

getTotalScriptIncome()

Get the income of all scripts.

getWeakenTime(host)

Get the execution time of a weaken() call.

grow(host, opts)

Spoof money in a server's bank account, increasing the amount available.

growthAnalyze(host, multiplier, cores)

Calculate the number of grow threads needed for a given multiplicative growth factor.

growthAnalyzeSecurity(threads, host, cores)

Calculate the security increase for a number of grow threads.

hack(host, opts)

Steal a server's money.

hackAnalyze(host)

Get the part of money stolen with a single thread.

hackAnalyzeChance(host)

Get the chance of successfully hacking a server.

hackAnalyzeSecurity(threads, host)

Get the security increase for a number of threads.

hackAnalyzeThreads(host, hackAmount)

Calculate the decimal number of threads needed to hack a specified amount of money from a target host.

hasRootAccess(host)

Check if you have root access on a server.

hasTorRouter()

Returns whether the player has access to the darkweb.

httpworm(host)

Runs HTTPWorm.exe on a server.

isLogEnabled(fn)

Checks the status of the logging for the given NS function.

isRunning(script, host, args)

Check if a script is running.

kill(pid)

Terminate the script with the provided PID.

kill(filename, host, args)

Terminate the script(s) with the provided filename, host, and script arguments.

killall(host, safetyGuard)

Terminate all scripts on a server.

ls(host, substring)

List files on a server.

mv(host, source, destination)

Move a file on the target server.

nextPortWrite(port)

Listen for a port write.

nuke(host)

Runs NUKE.exe on a server.

peek(portNumber)

Get a copy of the data from a port without popping it.

print(args)

Prints one or more values or variables to the scripts logs.

printf(format, args)

Prints a formatted string to the scripts logs.

printRaw(node)

Prints a ReactNode to the script logs.

prompt(txt, options)

Prompt the player with an input modal.

ps(host)

List running scripts on a server.

ramOverride(ram)

Change the current static RAM allocation of the script.

read(filename)

Read content of a file.

readPort(portNumber)

Read data from a port.

relaysmtp(host)

Runs relaySMTP.exe on a server.

rm(name, host)

Delete a file.

run(script, threadOrOptions, args)

Start another script on the current server.

scan(host, returnOpts)

Get the list of hostnames or IP addresses connected to a server. This function does not return darknet servers (e.g., darkweb). Use probe if you want to list darknet servers.

scp(files, destination, source)

Copy file between servers.

scriptKill(script, host)

Kill all scripts with a filename.

scriptRunning(script, host)

Check if any script with a filename is running.

self()

Returns the currently running script.

serverExists(host)

Returns a boolean denoting whether or not the specified server exists.

share()

Share the server's ram with your factions to increase the reputation gain rate of faction work. This boost is applied to all faction work of all factions.

sleep(millis)

Suspends the script for n milliseconds.

spawn(script, threadOrOptions, args)

Terminate current script and start another in a defined number of milliseconds.

sprintf(format, args)

Format a string.

sqlinject(host)

Runs SQLInject.exe on a server.

toast(msg, variant, duration)

Queue a toast (bottom-right notification).

tprint(args)

Prints one or more values or variables to the Terminal.

tprintf(format, values)

Prints a raw value or a variable to the Terminal.

tprintRaw(node)

Prints a ReactNode to the terminal.

tryWritePort(portNumber, data)

Attempt to write to a port.

vsprintf(format, args)

Format a string with an array of arguments.

weaken(host, opts)

Reduce a server's security level.

weakenAnalyze(threads, cores)

Predict the effect of weaken.

wget(url, target, host)

Download a file from the internet.

write(filename, data, mode)

Write data to a file.

writePort(portNumber, data)

Write data to a port.