mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-11 10:13:52 +01:00
65cd14e33b
* Add specific types for sleeve tasks * Moved LocationName enum to overall enums file * Add LocationName enum to those provided to player * remove trailing s on CompanyPosNames enum (now CompanyPosName, in line with LocationName) * Also regenerated all ns documentation. This leads to an expected error when checking for generated files, because PRs should not normally touch markdown files. Also leads to a lint failure in generated file bitburner.d.ts * also removed some exporting from NetscriptDefinitions.d.ts for anything that wasn't imported somewhere else.
73 lines
1.6 KiB
Markdown
73 lines
1.6 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 servers connected to a server.
|
|
|
|
<b>Signature:</b>
|
|
|
|
```typescript
|
|
scan(host?: string): string[];
|
|
```
|
|
|
|
## Parameters
|
|
|
|
| Parameter | Type | Description |
|
|
| --- | --- | --- |
|
|
| host | string | Optional. Hostname of the server to scan, default to current server. |
|
|
|
|
<b>Returns:</b>
|
|
|
|
string\[\]
|
|
|
|
Returns an array of hostnames.
|
|
|
|
## Remarks
|
|
|
|
RAM cost: 0.2 GB
|
|
|
|
Returns an array containing the hostnames of all servers that are one node way from the specified target server. The hostnames in the returned array are strings.
|
|
|
|
## Example 1
|
|
|
|
|
|
```ts
|
|
// NS1
|
|
// All servers that are one hop from the current server.
|
|
tprint("Neighbors of current server.");
|
|
var neighbor = scan();
|
|
for (var i = 0; i < neighbor.length; i++) {
|
|
tprint(neighbor[i]);
|
|
}
|
|
// All neighbors of n00dles.
|
|
var target = "n00dles";
|
|
neighbor = scan(target);
|
|
tprintf("Neighbors of %s.", target);
|
|
for (var i = 0; i < neighbor.length; i++) {
|
|
tprint(neighbor[i]);
|
|
}
|
|
```
|
|
|
|
## Example 2
|
|
|
|
|
|
```ts
|
|
// NS2
|
|
// 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 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]);
|
|
}
|
|
```
|
|
|