mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 14:59:16 +02:00
127 lines
2.8 KiB
Markdown
127 lines
2.8 KiB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
|
|
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [scan](./bitburner.ns.scan.md)
|
|
|
|
## NS.scan() method
|
|
|
|
Get the list of hostnames or IP addresses connected to a server. This function does not return darknet servers (e.g., darkweb). Use [probe](./bitburner.darknet.probe.md) if you want to list darknet servers.
|
|
|
|
**Signature:**
|
|
|
|
```typescript
|
|
scan(host?: string | null, returnOpts?: HostReturnOptions): string[];
|
|
```
|
|
|
|
## Parameters
|
|
|
|
<table><thead><tr><th>
|
|
|
|
Parameter
|
|
|
|
|
|
</th><th>
|
|
|
|
Type
|
|
|
|
|
|
</th><th>
|
|
|
|
Description
|
|
|
|
|
|
</th></tr></thead>
|
|
<tbody><tr><td>
|
|
|
|
host
|
|
|
|
|
|
</td><td>
|
|
|
|
string \| null
|
|
|
|
|
|
</td><td>
|
|
|
|
_(Optional)_ Optional. Hostname/IP of the server to scan, default to current server.
|
|
|
|
|
|
</td></tr>
|
|
<tr><td>
|
|
|
|
returnOpts
|
|
|
|
|
|
</td><td>
|
|
|
|
[HostReturnOptions](./bitburner.hostreturnoptions.md)
|
|
|
|
|
|
</td><td>
|
|
|
|
_(Optional)_ Optional. Controls whether the function returns IPs.
|
|
|
|
|
|
</td></tr>
|
|
</tbody></table>
|
|
|
|
**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
|
|
|
|
|
|
```js
|
|
// 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]);
|
|
}
|
|
```
|
|
|