Add documentation, screenshots and changelog for 1.0.0
README with install, quick start, keys, command reference and troubleshooting; docs/how-it-works.md explains the scan in detail. The screenshots show made-up devices only. The help line now drops hints that do not fit instead of cutting one in half, and the timeline no longer prints a new device's address twice. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e34ba75b7b
commit
343acd9a55
9 files changed
+428
-83
No files matched your search
@@ -0,0 +1,18 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 1.0.0 – 2026-10-26
|
||||||
|
|
||||||
|
First release.
|
||||||
|
|
||||||
|
- Interactive device list with live updates, auto-scan, sorting, filtering and
|
||||||
|
selectable columns.
|
||||||
|
- Fast scan: ICMP sweep plus the kernel's ARP table, TCP probe for routed ranges, no root
|
||||||
|
needed.
|
||||||
|
- Names via mDNS, NetBIOS and reverse DNS; Bonjour service discovery.
|
||||||
|
- Vendors from the IEEE registry (`nscan oui update`); Apple models via Bonjour, also
|
||||||
|
for devices with private MAC addresses.
|
||||||
|
- Custom names, whitelist, tracking with notifications, cumulative mode.
|
||||||
|
- Network timeline of the last 48 hours or 30 days.
|
||||||
|
- Continuous ping, TCP port scan, Wake-on-LAN, open in browser or SSH.
|
||||||
|
- Export as JSON and CSV; `nscan scan -json|-csv` for scripts.
|
||||||
|
- Commands `scan`, `ping`, `ports`, `wol`, `interfaces`, `oui` and `version`.
|
||||||
@@ -1,113 +1,286 @@
|
|||||||
# nscan
|
# nscan
|
||||||
|
|
||||||
A network scanner for the terminal, modeled on [IP Scanner](https://10base-t.com/ipscanner/):
|
**A fast network scanner for the terminal.** nscan finds every device on your local
|
||||||
it finds the devices on the local network and shows name, IP, MAC, vendor, response time and
|
network in a few seconds and shows its name, IP and MAC address, vendor, model, response
|
||||||
Bonjour services – as an interactive interface (TUI) or as a one-off table/JSON/CSV.
|
time and Bonjour services. It keeps a live list that updates itself, remembers devices
|
||||||
|
across runs and records who came and went.
|
||||||
|
|
||||||
## Build
|

|
||||||
|
|
||||||
|
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
|
```sh
|
||||||
go build -o nscan .
|
curl -fLo nscan https://git.micw.org/mike/nscan/releases/download/1.0.0/nscan-darwin-arm64
|
||||||
./nscan # interactive interface
|
chmod +x nscan
|
||||||
|
sudo mv nscan /usr/local/bin/
|
||||||
```
|
```
|
||||||
|
|
||||||
Requires Go 1.26 or newer. Runs on macOS and Linux, with limitations also on the BSDs and
|
The binaries are self-contained and need nothing else installed. On macOS, a file downloaded with a
|
||||||
Windows. No root privileges needed.
|
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.
|
||||||
|
|
||||||
## Features
|
### From source
|
||||||
|
|
||||||
| IP Scanner | nscan |
|
Requires Go 1.26 or newer.
|
||||||
|------------------------------|----------------------------------------------------------|
|
|
||||||
| Fast LAN scan | ICMP sweep + ARP cache, results appear live |
|
|
||||||
| Name, IP, MAC, Last Seen | plus vendor (OUI), ping time, Bonjour services |
|
|
||||||
| Custom names | `n` – stored permanently |
|
|
||||||
| Show/hide columns, sorting | `v` and `s`/`S` |
|
|
||||||
| Ping, port scan, Wake on LAN | `i`, `p`, `o` (also as `nscan ping/ports/wol`) |
|
|
||||||
| Bonjour services | DNS-SD discovery, listed in each device's details |
|
|
||||||
| Custom network ranges | `-r 10.0.0.0/24,10.0.5.10-50` or key `R` |
|
|
||||||
| Cumulative mode | `c` – also shows devices that are gone |
|
|
||||||
| Whitelist | `w` marks a device, `W` hides known devices |
|
|
||||||
| Track Device | `t` – terminal bell when a device misses 2 scans in a row or comes back |
|
|
||||||
| New device notifications | event line + bell |
|
|
||||||
| Network DVR (timeline) | `h` – one bar per hour/day, height = number of changes, `░` = not monitored |
|
|
||||||
| Open devices in browser/VNC | `b` browser, `x` SSH |
|
|
||||||
| Export | `e` writes JSON + CSV; `nscan scan -json/-csv` |
|
|
||||||
|
|
||||||
## Colors
|
```sh
|
||||||
|
git clone https://git.micw.org/mike/nscan.git
|
||||||
|
cd nscan
|
||||||
|
go build -o nscan .
|
||||||
|
```
|
||||||
|
|
||||||
The interface uses the [mwxcol](https://git.micw.org/mike/mwxcol) palette (`internal/tui/theme.go`):
|
## Quick start
|
||||||
green = online/new/ok, red = gone/error, yellow = tracked/warning, blue = headings, times and
|
|
||||||
keys, violet = accent and Bonjour services, grey = secondary text, `dark` = offline. The selection
|
```sh
|
||||||
is white on `darker` with a violet pointer, like the palette's fzf theme. Plain text and the
|
nscan oui update # once: download the vendor database (about 40,000 entries)
|
||||||
background come from the terminal – the mwxcol profile (background `#252528`) matches.
|
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.
|
||||||
|
|
||||||
|
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 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
|
## How it scans
|
||||||
|
|
||||||
1. **ICMP echo** to every address (two rounds). On macOS and most Linux distributions this works
|
1. **ICMP echo** to every address in the range, two rounds, at about 2500 packets per
|
||||||
without root through unprivileged ICMP sockets.
|
second.
|
||||||
2. **ARP cache**: every packet sent makes the kernel resolve the MAC address, so devices on the
|
2. **ARP table**: every packet makes the kernel resolve the target's MAC address. nscan
|
||||||
local segment are found even if they ignore pings.
|
reads the kernel's table, so devices that drop pings are found too.
|
||||||
3. **TCP probe** (ports 80, 443, 22, 445, 139, 62078) for addresses outside the local segment.
|
3. **TCP probe** for addresses outside the local segment, where ARP cannot reach.
|
||||||
4. **Names** via mDNS (a unicast query to each device), NetBIOS (Windows/Samba) and reverse DNS.
|
4. **Names** via mDNS, NetBIOS and reverse DNS, all at the same time.
|
||||||
5. **Bonjour**: a DNS-SD query for all service types on the network.
|
5. **Bonjour**: a DNS-SD query for every service type on the network, running in the
|
||||||
6. **Models**: Apple devices announce their model (e.g. `MacBookAir10,1`) in a Bonjour
|
background from the start.
|
||||||
`_device-info` record, which nscan asks each named device for.
|
6. **Models**: Apple devices announce their model in a `_device-info` record.
|
||||||
|
|
||||||
Without `-r`, nscan scans the network of the interface with the default route; networks larger
|
Sending never waits for replies, so the time a scan takes does not depend on how many
|
||||||
than /20 are narrowed to the local /24. `nscan interfaces` lists the alternatives for `-i`.
|
addresses are empty. [docs/how-it-works.md](docs/how-it-works.md) explains each step,
|
||||||
|
the timing and the trade-offs in detail.
|
||||||
|
|
||||||
## Commands
|
## Vendors and models
|
||||||
|
|
||||||
```text
|
The vendor column comes from the IEEE list of MAC address prefixes, which nscan does not
|
||||||
nscan [-i en0] [-r 192.168.1.0/24] [-interval 1m] interactive interface
|
ship. Download it once:
|
||||||
nscan scan [-json|-csv] scan once
|
|
||||||
nscan ping [-c 5] fritz.box ping
|
|
||||||
nscan ports [-p top|1-1024|all|22,80] 192.168.1.10 port scan
|
|
||||||
nscan wol aa:bb:cc:dd:ee:ff | "NAS" Wake-on-LAN (also by custom name)
|
|
||||||
nscan interfaces list interfaces
|
|
||||||
nscan oui update | import <file> | lookup <mac> vendor database
|
|
||||||
```
|
|
||||||
|
|
||||||
## Vendor database
|
|
||||||
|
|
||||||
The vendor column needs the IEEE list of MAC prefixes:
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./nscan oui update
|
nscan oui update
|
||||||
```
|
```
|
||||||
|
|
||||||
If the IEEE server blocks the download, fetch
|
If the IEEE server refuses the download, fetch
|
||||||
<https://standards-oui.ieee.org/oui/oui.csv> in a browser and import it:
|
<https://standards-oui.ieee.org/oui/oui.csv> in a browser and import it with
|
||||||
|
`nscan oui import ~/Downloads/oui.csv`.
|
||||||
|
|
||||||
```sh
|
Phones, tablets and laptops often use a **private (randomized) MAC address** for each
|
||||||
./nscan oui import ~/Downloads/oui.csv
|
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*.
|
||||||
Random ("private") MAC addresses, which iPhones, Macs and Android devices use per Wi-Fi
|
|
||||||
network, carry no vendor; nscan shows them as *Private address* even without the database.
|
|
||||||
If such a device announces an Apple model via Bonjour, the vendor column shows that instead,
|
|
||||||
e.g. *Apple MacBookAir10,1*.
|
|
||||||
|
|
||||||
## Data
|
## Data
|
||||||
|
|
||||||
Custom names, whitelist, tracking, first/last seen and the history (30 days) are kept in
|
nscan keeps its state in `~/.config/nscan/` (or `$XDG_CONFIG_HOME/nscan`, or
|
||||||
`~/.config/nscan/` (or `$XDG_CONFIG_HOME/nscan`, or `$NSCAN_DIR`):
|
`$NSCAN_DIR`):
|
||||||
`devices.json`, `events.jsonl`, `oui.tsv`.
|
|
||||||
|
|
||||||
## Notes
|
| 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 |
|
||||||
|
|
||||||
- **macOS "Local Network"**: if nscan finds nothing but your own machine, your terminal app
|
Devices are keyed by MAC address, so a custom name follows a device when its IP address
|
||||||
needs permission under *System Settings → Privacy & Security → Local Network*. Without it,
|
changes. Exports (<kbd>e</kbd>) go to `nscan-<date>-<time>.json` and `.csv`.
|
||||||
macOS also returns an empty ARP cache.
|
|
||||||
- **ARP cache**: devices found only through the ARP cache ("via arp" in the details) may still
|
|
||||||
appear online for a few minutes after they leave, until the kernel drops the entry (macOS: up
|
|
||||||
to 20 minutes).
|
|
||||||
- **Linux without ICMP permission** (`net.ipv4.ping_group_range`): nscan falls back to UDP
|
|
||||||
packets to trigger ARP; ping times are missing then.
|
|
||||||
- Only scan networks you are allowed to scan.
|
|
||||||
|
|
||||||
## Development
|
## 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
|
```sh
|
||||||
go test ./...
|
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 1.0.1
|
||||||
|
```
|
||||||
|
|
||||||
|
See [CHANGELOG.md](CHANGELOG.md) for what changed in each version.
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 194 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 151 KiB |
@@ -0,0 +1,143 @@
|
|||||||
|
# How nscan scans
|
||||||
|
|
||||||
|
The short version: nscan never waits for a single device. It sends a probe to every
|
||||||
|
address at once, collects whatever answers on the side, and lets the kernel find the
|
||||||
|
devices that do not answer. This page explains each step, where the time goes, and what
|
||||||
|
the approach cannot do.
|
||||||
|
|
||||||
|
## Why a naive scan is slow
|
||||||
|
|
||||||
|
`ping` sends one packet and waits up to a second for the reply before it moves on. Most
|
||||||
|
addresses in a network are empty, so most of that time is spent waiting for nothing. A
|
||||||
|
/24 has 254 addresses, which comes to over four minutes. Even 32 pings in parallel take
|
||||||
|
eight seconds, and the result still misses every device whose firewall drops pings.
|
||||||
|
|
||||||
|
## The sweep
|
||||||
|
|
||||||
|
### Sending and receiving are separate
|
||||||
|
|
||||||
|
nscan opens a single ICMP socket. One goroutine writes an echo request to every address
|
||||||
|
in the range. A second goroutine reads every reply that arrives, in whatever order.
|
||||||
|
|
||||||
|
Each request carries its own send time in the payload (`internal/scanner/icmp.go`), so a
|
||||||
|
reply is enough to compute the round-trip time. nscan keeps no timer and no state per
|
||||||
|
address. [ZMap](https://zmap.io) and [masscan](https://github.com/robertdavidgraham/masscan)
|
||||||
|
are built on the same idea.
|
||||||
|
|
||||||
|
The socket is an *unprivileged* ICMP socket (`SOCK_DGRAM` with `IPPROTO_ICMP`), which
|
||||||
|
macOS allows for every user and Linux for the groups in `net.ipv4.ping_group_range`. So
|
||||||
|
nscan needs no root and no setuid bit.
|
||||||
|
|
||||||
|
### About 2500 packets per second
|
||||||
|
|
||||||
|
After every eight packets, nscan pauses for 3 ms. A /24 is sent in about 0.1 s, a /20
|
||||||
|
(4094 addresses) in about 1.6 s.
|
||||||
|
|
||||||
|
Sending faster would not help. Before the first packet to an address can leave, the
|
||||||
|
kernel has to find its MAC address with an ARP request, and the room it has for packets
|
||||||
|
waiting on ARP is limited. Flood it and the kernel drops packets, and devices go missing
|
||||||
|
from the result.
|
||||||
|
|
||||||
|
### ARP finds the quiet devices
|
||||||
|
|
||||||
|
This is the actual trick. Every packet to an address on the local segment makes the
|
||||||
|
kernel send an ARP request: *who has 192.168.1.23?* Every device has to answer that,
|
||||||
|
even one whose firewall drops all pings, or it could not talk to anyone on the network.
|
||||||
|
|
||||||
|
While the sweep runs, nscan reads the kernel's ARP table every 600 ms:
|
||||||
|
|
||||||
|
| System | Source |
|
||||||
|
|--------|-----------------------------------------------------------------|
|
||||||
|
| macOS | the routing table via `sysctl` (`NET_RT_FLAGS`, `RTF_LLINFO`), falling back to `arp -an` |
|
||||||
|
| Linux | `/proc/net/arp` |
|
||||||
|
|
||||||
|
Every complete entry is a device, with its MAC address. nscan never builds an ARP packet
|
||||||
|
itself, which would take a raw socket and root. It lets the kernel do that work.
|
||||||
|
|
||||||
|
### Fixed waits instead of per-address timeouts
|
||||||
|
|
||||||
|
```text
|
||||||
|
0.0 s round 1 echo request to every address ~0.1 s
|
||||||
|
wait late replies, ARP table polling 0.75 s
|
||||||
|
round 2 only the addresses still silent ~0.1 s
|
||||||
|
wait late replies, ARP table polling 1.5 s
|
||||||
|
~2.5 s sweep done
|
||||||
|
```
|
||||||
|
|
||||||
|
The second round catches packets lost on Wi-Fi, and devices that were asleep and missed
|
||||||
|
their first ARP request. Both waits are fixed, so empty addresses cost nothing extra:
|
||||||
|
a /24 with 3 devices takes as long as one with 200. `-wait` sets the second wait; the first
|
||||||
|
is half of it.
|
||||||
|
|
||||||
|
Without any ICMP permission, nscan sends one UDP datagram to port 9 of each address
|
||||||
|
instead. That still triggers ARP, so devices are found, only without response times.
|
||||||
|
|
||||||
|
## Outside the local segment
|
||||||
|
|
||||||
|
ARP only reaches the local segment, and routers and firewalls often drop ICMP. For
|
||||||
|
addresses in a routed range (`-r 10.20.0.0/24` from somewhere else) that stayed silent,
|
||||||
|
nscan tries TCP connects to ports 80, 443, 22, 445, 139 and 62078, up to 256 hosts at a
|
||||||
|
time, with 800 ms per host. A refused connection counts too: the host had to be there
|
||||||
|
to refuse it.
|
||||||
|
|
||||||
|
## Names
|
||||||
|
|
||||||
|
As soon as the sweep is done, three lookups run at the same time:
|
||||||
|
|
||||||
|
| Source | How |
|
||||||
|
|-------------|---------------------------------------------------------------------|
|
||||||
|
| mDNS | a unicast `PTR` query for the reverse name to port 5353 of each device |
|
||||||
|
| NetBIOS | a node status request (`NBSTAT`) to UDP port 137 of each device |
|
||||||
|
| Reverse DNS | the system resolver, 32 lookups at a time |
|
||||||
|
|
||||||
|
mDNS and NetBIOS work like the sweep: all queries go out of one socket at once, and the
|
||||||
|
answers are collected until a shared deadline of 1.5 s. The interface shows the first
|
||||||
|
name it has, preferring a custom name, then mDNS, NetBIOS and DNS. Suffixes such as
|
||||||
|
`.local`, `.lan` or `.fritz.box` are dropped.
|
||||||
|
|
||||||
|
## Bonjour services
|
||||||
|
|
||||||
|
A DNS-SD browse starts in the background together with the sweep. It asks for
|
||||||
|
`_services._dns-sd._udp.local` to learn every service type on the network, then for the
|
||||||
|
instances of each type, and resolves them to addresses.
|
||||||
|
|
||||||
|
The queries go to the mDNS multicast group from an ephemeral port instead of port 5353.
|
||||||
|
Responders then answer by unicast ([RFC 6762, section 6.7](https://www.rfc-editor.org/rfc/rfc6762#section-6.7)),
|
||||||
|
so nscan does not compete with the system's mDNS daemon for the port.
|
||||||
|
|
||||||
|
## Models
|
||||||
|
|
||||||
|
Apple devices publish a `_device-info._tcp` record with their model, e.g.
|
||||||
|
`model=MacBookAir10,1`. For every device with an mDNS or service name, nscan sends a
|
||||||
|
unicast `TXT` query for `<name>._device-info._tcp.local.` and waits up to one second.
|
||||||
|
|
||||||
|
This is what still identifies a device behind a private MAC address. Such an address has
|
||||||
|
the *locally administered* bit set, carries no vendor prefix, and changes per Wi-Fi
|
||||||
|
network. The model does not change.
|
||||||
|
|
||||||
|
## Where the time goes
|
||||||
|
|
||||||
|
For a /24 on a home network:
|
||||||
|
|
||||||
|
| Phase | Time | Runs |
|
||||||
|
|----------------------|-----------------|------------------------------|
|
||||||
|
| Ping and ARP | about 2.5 s | first |
|
||||||
|
| Bonjour | 3.5 s | in parallel from the start |
|
||||||
|
| Names | 1.5 s, rarely up to 3 s | after the sweep |
|
||||||
|
| Models | up to 1 s | after the names |
|
||||||
|
|
||||||
|
A full scan is done in about five seconds. The list fills up much sooner, though: every
|
||||||
|
device is sent to the interface the moment it is found, so most appear within the first
|
||||||
|
second.
|
||||||
|
|
||||||
|
## Trade-offs
|
||||||
|
|
||||||
|
- **Stale ARP entries.** The kernel keeps ARP entries for a while after a device left
|
||||||
|
(macOS: up to 20 minutes). A device found only that way (*via arp* in the details) can
|
||||||
|
appear online for that long.
|
||||||
|
- **Missing a reply is possible.** A device that is asleep through both rounds and every
|
||||||
|
ARP retry is reported missing. That is why nscan only reports a device as gone after it
|
||||||
|
missed two scans in a row.
|
||||||
|
- **Load.** 2500 small packets per second is nothing for a wired network and fine for
|
||||||
|
Wi-Fi, but a scan of a large range still sends one packet to every address in it. Only
|
||||||
|
scan networks you are allowed to scan.
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 422 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 216 KiB |
@@ -219,7 +219,8 @@ func (m *model) viewHistory() string {
|
|||||||
for i := len(b.events) - 1; i >= 0 && len(b.events)-1-i < avail; i-- {
|
for i := len(b.events) - 1; i >= 0 && len(b.events)-1-i < avail; i-- {
|
||||||
e := b.events[i]
|
e := b.events[i]
|
||||||
line := " " + renderEvent(e, false)
|
line := " " + renderEvent(e, false)
|
||||||
if e.IP != "" && e.Label != e.IP {
|
// renderEvent already names the address of a new device
|
||||||
|
if e.IP != "" && e.Label != e.IP && e.Kind != store.EventNew {
|
||||||
line += styleMuted.Render(" " + e.IP)
|
line += styleMuted.Render(" " + e.IP)
|
||||||
}
|
}
|
||||||
lines = append(lines, styleTime.Render(" "+e.Time.Format("15:04"))+line)
|
lines = append(lines, styleTime.Render(" "+e.Time.Format("15:04"))+line)
|
||||||
|
|||||||
+11
-1
@@ -356,12 +356,22 @@ func (m *model) footer(hints ...string) string {
|
|||||||
}
|
}
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
b.WriteString(" ")
|
b.WriteString(" ")
|
||||||
|
width := 1
|
||||||
for i, h := range hints {
|
for i, h := range hints {
|
||||||
key, label, _ := strings.Cut(h, " ")
|
key, label, _ := strings.Cut(h, " ")
|
||||||
|
w := lipgloss.Width(h)
|
||||||
|
if i > 0 {
|
||||||
|
w += 3
|
||||||
|
}
|
||||||
|
// drop the hints that do not fit whole instead of cutting one in half
|
||||||
|
if m.w > 0 && width+w > m.w {
|
||||||
|
break
|
||||||
|
}
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
b.WriteString(styleMuted.Render(" · "))
|
b.WriteString(styleMuted.Render(" · "))
|
||||||
}
|
}
|
||||||
b.WriteString(styleKey.Render(key) + " " + styleDim.Render(label))
|
b.WriteString(styleKey.Render(key) + " " + styleDim.Render(label))
|
||||||
|
width += w
|
||||||
}
|
}
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
@@ -520,7 +530,7 @@ func (m *model) viewHelp() string {
|
|||||||
}
|
}
|
||||||
lines = append(lines, "",
|
lines = append(lines, "",
|
||||||
styleDim.Render(" Symbols: ")+styleOnline.Render("●")+" online "+styleMuted.Render("○")+" offline "+
|
styleDim.Render(" Symbols: ")+styleOnline.Render("●")+" online "+styleMuted.Render("○")+" offline "+
|
||||||
styleTracked.Render("⚑")+" tracked "+styleMuted.Render("✓")+" Whitelist",
|
styleTracked.Render("⚑")+" tracked "+styleMuted.Render("✓")+" whitelisted",
|
||||||
styleDim.Render(" Data: ")+m.cfg.Store.Dir())
|
styleDim.Render(" Data: ")+m.cfg.Store.Dir())
|
||||||
if m.cfg.Version != "" {
|
if m.cfg.Version != "" {
|
||||||
lines = append(lines, styleDim.Render(" Version: ")+m.cfg.Version)
|
lines = append(lines, styleDim.Render(" Version: ")+m.cfg.Version)
|
||||||
|
|||||||
Reference in new issue
Block a user