Files
bitburner-src/markdown/bitburner.ns.scan.md
Michael Taylor dcd2f33f7c CODEBASE: Update api-documentor and api-extractor (#2320)
* Update api-documentor and api-extractor. #1566 follow-up.

I have verified that the HTML/markdown table generation bug in
[#4878](https://github.com/microsoft/rushstack/issues/4878) in rushstack
for api-documentor has been fixed as per rushstack#5256. The testcase
[repro](https://github.com/catloversg/api-documenter-bug-pr-4578) now
produces the correct expected output.

I have confirmed that the generated output in bitburner from
`npm run doc` now generated HTML tables, and correctly inserts
a blank line between the </table> and the follow line (e.g. Returns).

Stylisticly it could use some whitespace, but it is correctly rendered.

This commit is only the updated packages, not the updated generated
documentation. I assume that is automatically generated by the GitHub
workflow.

* Follow up to 5f732a6f35, include `npm run doc` changed docs.

* Add missing license info

* Fix React warning

---------

Co-authored-by: CatLover <152669316+catloversg@users.noreply.github.com>
2025-09-26 14:52:39 -07:00

2.7 KiB

Home > bitburner > NS > scan

NS.scan() method

Get the list of hostnames or IP addresses connected to a server.

Signature:

scan(host?: string | null, returnOpts?: HostReturnOptions): string[];

Parameters

Parameter

Type

Description

host

string | null

(Optional) Optional. Hostname/IP of the server to scan, default to current server.

returnOpts

HostReturnOptions

(Optional) Optional. Controls whether the function returns IPs.

Returns:

string[]

Returns an array of hostnames.

Remarks

RAM cost: 0.2 GB

Returns an array containing the hostnames or IP addresses of all servers that are one node way from the specified target server. The hostnames/IPs in the returned array are strings. Returns hostnames by default.

The server network is a tree graph with the home server at the root. The parent node is always the first item of the returned array.

For example, let's say the network looks like this:

home
--n00dles
--joesguns
----CSEC
------omega-net

ns.scan("home"): ["n00dles", "joesguns"]: "home" is the root, so it does not have a parent node.

ns.scan("n00dles"): ["home"]: "home" is the parent node of "n00dles".

ns.scan("joesguns"): ["home", "CSEC"]: "home" is the parent node of "joesguns".

ns.scan("CSEC"): ["joesguns", "omega-net"]: "joesguns" is the parent node of "CSEC".

ns.scan("omega-net"): ["CSEC"]: "CSEC" is the parent node of "omega-net".

If you run the "scan-analyze" command at home, it won't show all servers due to its limited maximum depth. You can use this function with BFS (Breadth-first search) or DFS (Depth-first search) to traverse the network and discover all servers.

Example

// All servers that are one hop from the current server.
ns.tprint("Neighbors of current server.");
let neighbor = ns.scan();
for (let i = 0; i < neighbor.length; i++) {
    ns.tprint(neighbor[i]);
}
// All servers that are one hop from the current server, but by IP address.
ns.tprint("IPs of current server's neighbors.");
let neighbor = ns.scan(null, { returnByIP: true });
for (let i = 0; i < neighbor.length; i++) {
    ns.tprint(neighbor[i]);
}
// All neighbors of n00dles.
const target = "n00dles";
neighbor = ns.scan(target);
ns.tprintf("Neighbors of %s.", target);
for (let i = 0; i < neighbor.length; i++) {
    ns.tprint(neighbor[i]);
}