Files
nscan/README.md
T

114 lines
5.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# nscan
A network scanner for the terminal, modeled on [IP Scanner](https://10base-t.com/ipscanner/):
it finds the devices on the local network and shows name, IP, MAC, vendor, response time and
Bonjour services – as an interactive interface (TUI) or as a one-off table/JSON/CSV.
## Build
```sh
go build -o nscan .
./nscan # interactive interface
```
Requires Go 1.26 or newer. Runs on macOS and Linux, with limitations also on the BSDs and
Windows. No root privileges needed.
## Features
| IP Scanner | nscan |
|------------------------------|----------------------------------------------------------|
| 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
The interface uses the [mwxcol](https://git.micw.org/mike/mwxcol) palette (`internal/tui/theme.go`):
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
is white on `darker` with a violet pointer, like the palette's fzf theme. Plain text and the
background come from the terminal – the mwxcol profile (background `#252528`) matches.
## How it scans
1. **ICMP echo** to every address (two rounds). On macOS and most Linux distributions this works
without root through unprivileged ICMP sockets.
2. **ARP cache**: every packet sent makes the kernel resolve the MAC address, so devices on the
local segment are found even if they ignore pings.
3. **TCP probe** (ports 80, 443, 22, 445, 139, 62078) for addresses outside the local segment.
4. **Names** via mDNS (a unicast query to each device), NetBIOS (Windows/Samba) and reverse DNS.
5. **Bonjour**: a DNS-SD query for all service types on the network.
6. **Models**: Apple devices announce their model (e.g. `MacBookAir10,1`) in a Bonjour
`_device-info` record, which nscan asks each named device for.
Without `-r`, nscan scans the network of the interface with the default route; networks larger
than /20 are narrowed to the local /24. `nscan interfaces` lists the alternatives for `-i`.
## Commands
```text
nscan [-i en0] [-r 192.168.1.0/24] [-interval 1m] interactive interface
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
./nscan oui update
```
If the IEEE server blocks the download, fetch
<https://standards-oui.ieee.org/oui/oui.csv> in a browser and import it:
```sh
./nscan oui import ~/Downloads/oui.csv
```
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
Custom names, whitelist, tracking, first/last seen and the history (30 days) are kept in
`~/.config/nscan/` (or `$XDG_CONFIG_HOME/nscan`, or `$NSCAN_DIR`):
`devices.json`, `events.jsonl`, `oui.tsv`.
## Notes
- **macOS "Local Network"**: if nscan finds nothing but your own machine, your terminal app
needs permission under *System Settings → Privacy & Security → Local Network*. Without it,
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
```sh
go test ./...
```