nscan update installs the newest release from git.micw.org, nscan update -c only checks; --update and --check-update work as well. The download lands next to the running binary, is started once with --version and only then replaces it. Once a day an ordinary run asks in the background and mentions a newer release in the title bar and on stderr, only on a terminal and not with NSCAN_NO_UPDATE_CHECK set. selfupdate.go is goca's copyable template. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
314 lines
14 KiB
Markdown
314 lines
14 KiB
Markdown
# nscan
|
|
|
|
**A fast network scanner for the terminal.** nscan finds every device on your local
|
|
network in a few seconds and shows its name, IP and MAC address, vendor, model, response
|
|
time and Bonjour services. It keeps a live list that updates itself, remembers devices
|
|
across runs and records who came and went.
|
|
|
|

|
|
|
|
Modeled on [IP Scanner](https://10base-t.com/ipscanner/) for macOS, but it runs entirely
|
|
in the terminal, works on macOS and Linux, and needs no root privileges.
|
|
|
|
## Contents
|
|
|
|
- [Highlights](#highlights)
|
|
- [Install](#install)
|
|
- [Quick start](#quick-start)
|
|
- [The interface](#the-interface)
|
|
- [Command line](#command-line)
|
|
- [How it scans](#how-it-scans)
|
|
- [Vendors and models](#vendors-and-models)
|
|
- [Data](#data)
|
|
- [Troubleshooting](#troubleshooting)
|
|
- [Building and releasing](#building-and-releasing)
|
|
|
|
## Highlights
|
|
|
|
- **Fast**: devices appear within a second, and a full scan of a /24 network, names
|
|
included, takes about five seconds. ARP finds the devices that ignore pings too
|
|
([how?](docs/how-it-works.md)).
|
|
- **Knows what it sees**: names via mDNS, NetBIOS and DNS, vendors from the IEEE
|
|
registry, Apple models such as *MacBookAir10,1* even behind private MAC addresses,
|
|
and all Bonjour services on the network.
|
|
- **Remembers**: custom names, a whitelist for known devices, first/last seen, and a
|
|
cumulative mode that keeps devices visible after they leave.
|
|
- **Watches**: auto-scans every minute, rings the terminal bell for new devices, and
|
|
tracks chosen devices when they leave or come back.
|
|
- **Network DVR**: a timeline of the last 48 hours or 30 days that shows when devices
|
|
came and went, and when nothing was being monitored.
|
|
- **Tools built in**: continuous ping with a sparkline, TCP port scan, Wake-on-LAN, and
|
|
one key to open a device in the browser or over SSH.
|
|
- **Scriptable**: `nscan scan -json` or `-csv` for a one-off scan, plus `ping`, `ports`,
|
|
`wol` and `oui` as plain commands.
|
|
- **No root needed**: unprivileged ICMP sockets, and the kernel's ARP table instead of
|
|
raw packets.
|
|
|
|
## Install
|
|
|
|
### Binary
|
|
|
|
Download the file for your system from the
|
|
[latest release](https://git.micw.org/mike/nscan/releases/latest):
|
|
|
|
| System | File |
|
|
|-------------------------|----------------------|
|
|
| macOS, Apple silicon | `nscan-darwin-arm64` |
|
|
| macOS, Intel | `nscan-darwin-amd64` |
|
|
| Linux, x86-64 | `nscan-linux-amd64` |
|
|
| Linux, ARM64 (e.g. Pi) | `nscan-linux-arm64` |
|
|
|
|
```sh
|
|
curl -fLo nscan https://git.micw.org/mike/nscan/releases/download/1.0.2/nscan-darwin-arm64
|
|
chmod +x nscan
|
|
sudo mv nscan /usr/local/bin/
|
|
```
|
|
|
|
The binaries are self-contained and need nothing else installed. On macOS, a file downloaded with a
|
|
browser is quarantined and will not start, since it is not notarized. Clear the flag with
|
|
`xattr -d com.apple.quarantine nscan`. Files fetched with `curl` are not affected.
|
|
|
|
### From source
|
|
|
|
Requires Go 1.26 or newer.
|
|
|
|
```sh
|
|
git clone https://git.micw.org/mike/nscan.git
|
|
cd nscan
|
|
go build -o nscan .
|
|
```
|
|
|
|
### Updating
|
|
|
|
```sh
|
|
nscan update # download the newest release and replace the running binary
|
|
nscan update -c # only check
|
|
```
|
|
|
|
`--update` and `--check-update` work as well. If nscan lives in a directory you cannot
|
|
write to, such as `/usr/local/bin`, run `sudo nscan update`. The new binary is downloaded
|
|
next to the old one and started once with `--version` before it replaces the old one,
|
|
so a broken download never takes its place.
|
|
|
|
Once a day, nscan also asks git.micw.org in the background whether there is a newer
|
|
release. If so, it says so on the next run: in the title bar of the interface, and as a
|
|
line on stderr after a command. Nothing is installed without `nscan update`. The check
|
|
stays quiet when stderr is not a terminal (pipes, scripts, cron). Set
|
|
`NSCAN_NO_UPDATE_CHECK=1` to turn it off.
|
|
|
|
Self-update arrived in 1.0.2. Replace older versions by hand once.
|
|
|
|
## Quick start
|
|
|
|
```sh
|
|
nscan oui update # once: download the vendor database (about 40,000 entries)
|
|
nscan # open the interactive interface on the default network
|
|
```
|
|
|
|
nscan picks the interface with the default route and scans its network. Networks larger
|
|
than /20 are narrowed to your own /24. To scan something else:
|
|
|
|
```sh
|
|
nscan -i en1 # another interface
|
|
nscan -r 192.168.1.0/24 # another range
|
|
nscan -r 10.0.0.1-50,10.0.5.0/28 # several ranges at once
|
|
nscan scan # scan once, print a table, exit
|
|
```
|
|
|
|
> **macOS:** your terminal app needs permission under *System Settings → Privacy &
|
|
> Security → Local Network*. Without it, nscan finds nothing but your own machine.
|
|
|
|
## The interface
|
|
|
|
The list updates while a scan runs and rescans every minute. `●` marks devices that are
|
|
online, `○` those that are gone (shown in cumulative mode), `⚑` tracked devices and `✓`
|
|
whitelisted ones. New devices and tracked devices that come or go appear in the event
|
|
line at the bottom and ring the terminal bell. Each column is as wide as its content, and
|
|
the services get the rest of the line. In a narrow terminal, the widest of name, vendor
|
|
and services give way first.
|
|
|
|
Press <kbd>enter</kbd> for everything nscan knows about a device. That includes all of its
|
|
Bonjour services and the open ports from the last port scan.
|
|
|
|

|
|
|
|
<kbd>h</kbd> opens the timeline. Each bar is one hour (or day, with <kbd>z</kbd>): its height
|
|
is the number of changes, and its color tells whether more devices arrived or left.
|
|
Hatched stretches are times when nscan was not running. Select a bar with
|
|
<kbd>←</kbd>/<kbd>→</kbd> to see what happened then.
|
|
|
|

|
|
|
|
<kbd>i</kbd> pings the selected device continuously, with a sparkline of the response times.
|
|
<kbd>p</kbd> scans its TCP ports.
|
|
|
|

|
|
|
|
### Keys
|
|
|
|
| Key | Action |
|
|
|-----------------------------|------------------------------------------------------|
|
|
| <kbd>↑</kbd>/<kbd>↓</kbd>, <kbd>j</kbd>/<kbd>k</kbd> | select a device (also PgUp/PgDn, g/G) |
|
|
| <kbd>enter</kbd> | device details |
|
|
| <kbd>r</kbd> | scan now |
|
|
| <kbd>a</kbd> | auto-scan on/off |
|
|
| <kbd>c</kbd> | cumulative mode: also show devices that are gone |
|
|
| <kbd>s</kbd> / <kbd>S</kbd> | next sort column / reverse order |
|
|
| <kbd>/</kbd> | filter by name, IP, MAC, vendor or service |
|
|
| <kbd>n</kbd> | set a custom name |
|
|
| <kbd>t</kbd> | track: notify when the device leaves or returns |
|
|
| <kbd>w</kbd> / <kbd>W</kbd> | toggle whitelist / hide whitelisted devices |
|
|
| <kbd>p</kbd> | port scan |
|
|
| <kbd>i</kbd> | continuous ping |
|
|
| <kbd>o</kbd> | Wake-on-LAN |
|
|
| <kbd>b</kbd> | open in the browser |
|
|
| <kbd>x</kbd> | open an SSH session |
|
|
| <kbd>h</kbd> | history (network timeline) |
|
|
| <kbd>v</kbd> | show/hide columns |
|
|
| <kbd>R</kbd> | scan a different address range |
|
|
| <kbd>e</kbd> | export as JSON and CSV |
|
|
| <kbd>?</kbd> | help |
|
|
| <kbd>q</kbd> | quit |
|
|
|
|
A device counts as gone after it has been missing from two scans in a row. Single lost
|
|
replies are common on Wi-Fi.
|
|
|
|
### Colors
|
|
|
|
The interface uses the [mwxcol](https://git.micw.org/mike/mwxcol) palette: green for
|
|
online, new and ok, red for gone and errors, yellow for tracked devices and warnings,
|
|
blue for headings, times and keys, violet for accents and Bonjour services. Plain text and
|
|
the background come from your terminal. The mwxcol terminal profile (background
|
|
`#252528`) matches, as in the screenshots.
|
|
|
|
## Command line
|
|
|
|
```text
|
|
nscan [options] interactive interface (default)
|
|
nscan scan [options] scan once and print a table
|
|
nscan ping [-c N] <host> ping (ICMP, falls back to TCP without permission)
|
|
nscan ports [-p top] <host> TCP port scan
|
|
nscan wol <mac|name> send a Wake-on-LAN magic packet
|
|
nscan interfaces list network interfaces
|
|
nscan oui update download the vendor database from the IEEE
|
|
nscan oui import <file> import oui.csv/oui.txt manually
|
|
nscan oui lookup <mac> show the vendor of a MAC address
|
|
nscan update [-c] install the newest release (-c: only check)
|
|
nscan version print the version
|
|
```
|
|
|
|
Options for the interface and `scan`:
|
|
|
|
| Option | Meaning |
|
|
|-------------------|------------------------------------------------------------|
|
|
| `-i <iface>` | interface (default: the one with the default route) |
|
|
| `-r <range>` | address range: CIDR, `a.b.c.d-e`, `a-b`, comma-separated |
|
|
| `-wait <dur>` | how long to wait for late replies (default `1.5s`) |
|
|
| `-no-names` | skip name resolution (mDNS, NetBIOS, DNS) |
|
|
| `-no-bonjour` | skip Bonjour service discovery |
|
|
| `-interval <dur>` | auto-scan interval, `0` = off (default `1m`) |
|
|
| `-export-dir <d>` | where <kbd>e</kbd> writes its files (default: current directory) |
|
|
| `-json`, `-csv` | output format of `scan` |
|
|
|
|
Some examples:
|
|
|
|
```sh
|
|
nscan scan -json | jq '.[] | select(.vendor == "Apple") | .ip'
|
|
nscan ping -c 10 192.168.1.20
|
|
nscan ports -p 1-1024 192.168.1.20 # also: top (about 90 well-known ports), all, 22,80,443
|
|
nscan wol "NAS" # by custom name, or by MAC address
|
|
nscan oui lookup 3c:a6:2f:00:00:00
|
|
```
|
|
|
|
`nscan scan` writes the table to stdout and progress to stderr, so it pipes cleanly. It
|
|
also updates the stored devices and the history, just like the interface.
|
|
|
|
## How it scans
|
|
|
|
1. **ICMP echo** to every address in the range, two rounds, at about 2500 packets per
|
|
second.
|
|
2. **ARP table**: every packet makes the kernel resolve the target's MAC address. nscan
|
|
reads the kernel's table, so devices that drop pings are found too.
|
|
3. **TCP probe** for addresses outside the local segment, where ARP cannot reach.
|
|
4. **Names** via mDNS, NetBIOS and reverse DNS, all at the same time.
|
|
5. **Bonjour**: a DNS-SD query for every service type on the network, running in the
|
|
background from the start.
|
|
6. **Models**: Apple devices announce their model in a `_device-info` record.
|
|
|
|
Sending never waits for replies, so the time a scan takes does not depend on how many
|
|
addresses are empty. [docs/how-it-works.md](docs/how-it-works.md) explains each step,
|
|
the timing and the trade-offs in detail.
|
|
|
|
## Vendors and models
|
|
|
|
The vendor column comes from the IEEE list of MAC address prefixes, which nscan does not
|
|
ship. Download it once:
|
|
|
|
```sh
|
|
nscan oui update
|
|
```
|
|
|
|
If the IEEE server refuses the download, fetch
|
|
<https://standards-oui.ieee.org/oui/oui.csv> in a browser and import it with
|
|
`nscan oui import ~/Downloads/oui.csv`.
|
|
|
|
Phones, tablets and laptops often use a **private (randomized) MAC address** for each
|
|
Wi-Fi network. Such an address carries no vendor, and nscan shows *Private address*.
|
|
Apple devices still announce their model via Bonjour, so nscan shows them as, for example,
|
|
*Apple iPhone15,3*. The details mark such addresses as *private, randomized*.
|
|
|
|
## Data
|
|
|
|
nscan keeps its state in `~/.config/nscan/` (or `$XDG_CONFIG_HOME/nscan`, or
|
|
`$NSCAN_DIR`):
|
|
|
|
| File | Contents |
|
|
|----------------|----------------------------------------------------------------|
|
|
| `devices.json` | every device seen: custom name, whitelist, tracking, model, first/last seen |
|
|
| `events.jsonl` | the history (new, back, gone, scans), kept for 30 days |
|
|
| `oui.tsv` | the vendor database |
|
|
|
|
Devices are keyed by MAC address, so a custom name follows a device when its IP address
|
|
changes. Exports (<kbd>e</kbd>) go to `nscan-<date>-<time>.json` and `.csv`.
|
|
|
|
The result of the daily update check is kept in the user cache directory
|
|
(`~/Library/Caches/nscan/update.json` on macOS, `~/.cache/nscan/update.json` on Linux).
|
|
Losing it only means asking once more.
|
|
|
|
## Troubleshooting
|
|
|
|
**Only my own machine shows up (macOS).** Grant your terminal app access under
|
|
*System Settings → Privacy & Security → Local Network* and restart it. Without that
|
|
permission, macOS also hides the ARP table.
|
|
|
|
**A device stays online after it left.** Devices found only through the ARP table
|
|
(*via arp* in the details) can appear online until the kernel drops the entry: on macOS
|
|
that takes up to 20 minutes.
|
|
|
|
**No ping times on Linux.** Unprivileged ICMP needs your group in
|
|
`net.ipv4.ping_group_range`, e.g. `sudo sysctl net.ipv4.ping_group_range="0 2147483647"`.
|
|
Without it, nscan still finds devices through ARP, but cannot measure response times.
|
|
|
|
**Vendor column says "Vendor database missing".** Run `nscan oui update`.
|
|
|
|
Only scan networks you are allowed to scan.
|
|
|
|
## Building and releasing
|
|
|
|
```sh
|
|
go test ./...
|
|
./build.sh # next patch version, all platforms, into ./bin
|
|
VERSION=1.1.0 ./build.sh # a minor or major step
|
|
```
|
|
|
|
`build.sh` builds static binaries for macOS and Linux (arm64 and amd64) into `./bin`,
|
|
named `nscan-<os>-<arch>`, with the version from `version.txt` compiled in. A plain
|
|
`go build` reports the version in `version.go`. Releases are published with
|
|
[mgsh](https://git.micw.org/mike/mgsh), which attaches everything in `./bin`:
|
|
|
|
```sh
|
|
./build.sh && mgsh release @micw $(cat version.txt)
|
|
```
|
|
|
|
See [CHANGELOG.md](CHANGELOG.md) for what changed in each version.
|