Usage Guide#

Installation#

Install from PyPI using pip or uv:

pip install lanspector
# Optional extras
pip install "lanspector[dashboard]"  # Dash 3+ LANdash web app
pip install "lanspector[pii]"        # Optional NLTK proper-noun NER

CLI Subcommands#

LANspector exposes a unified CLI powered by jsonargparse and typed dataclasses in lanspector.settings. Run lanspector <subcommand> --help for detailed flag descriptions.

Subcommands & Required Arguments#

Subcommand

Required Arguments

Default Outputs & Purpose

crawl

--path <dir> or --driver <file>

Saves ./<target>.db (if --fout omitted) and <fout_stem>_<timestamp>.xlsx (--summarize true by default); logs full output paths.

report

--databases '[a.db]'

Writes lanspector_report.xlsx (override with --output).

sunburst

--database <a.db>

Writes standalone offline lanspector_sunburst.html (override with --output).

compare

--database <a.db>

Prints diff counts and optionally writes --output drift.xlsx.

dashboard-prep

--databases '[a.db]'

Aggregates crawl databases into a LANdash SQLite store (default landash.sqlite). Run before dashboard.

dashboard

(none; defaults to ``landash.sqlite``)

Serves LANdash locally at http://127.0.0.1:8050 from a store built by dashboard-prep.

gui

(none)

Launches the optional Tkinter desktop GUI.

shares

--servers or --domains

Lists Windows SMB shares (optionally writes --output CSV/Excel).

# Minimal crawl: creates ./finance.db and ./finance_<timestamp>.xlsx and logs their paths
lanspector crawl --path /data/finance

# Resume an interrupted crawl in an existing SQLite database (skips completed paths)
lanspector crawl --path /data/finance --fout finance.db --resume true

# Explicit paths + interactive Plotly sunburst HTML
lanspector crawl --path /data/finance --fout finance.db --sunburst_html sunburst.html

lanspector report --databases '[finance.db]' --output audit.xlsx
lanspector sunburst --database finance.db --output sunburst.html --color_by age
lanspector compare --database finance.db --output drift.xlsx
lanspector dashboard-prep --databases '[finance.db]' --dashboard_db landash.sqlite
lanspector dashboard --dashboard_db landash.sqlite --port 8050
lanspector gui --database finance.db
lanspector shares --servers '[filesrv01]'

Configuration Files (--config & --print_config)#

Because the CLI is backed by jsonargparse, every subcommand supports YAML or JSON configuration files via --config <path>. Any flag passed on the command line overrides the value in the config file.

Sample configuration files live in the repository’s examples/ directory:

  • examples/crawl_config.yaml — Annotated single-share crawl configuration

  • examples/report_config.yaml — Multi-database Excel audit report configuration

  • examples/driver_shares.txt — Batch multi-share / server / domain driver file

You can also generate a complete starter YAML config for any subcommand with --print_config:

lanspector crawl --print_config > my_crawl.yaml
lanspector crawl --config my_crawl.yaml --path /data/finance

Example examples/crawl_config.yaml:

# Sample LANspector YAML configuration for `lanspector crawl`
#
# Usage:
#   lanspector crawl --config examples/crawl_config.yaml
#
# Override any field from the command line:
#   lanspector crawl --config examples/crawl_config.yaml --limit 100
#
# Generate a fresh template containing all options and defaults:
#   lanspector crawl --print_config > my_crawl.yaml

# Required: directory or Windows UNC share to crawl (alternatively set `driver`)
path: /path/to/fileshare

# Output SQLite database (.db / .sqlite / .sqlite3), .csv, or .xlsx
# If omitted on the CLI, defaults to ./<sanitized_target_name>.db
fout: finance_crawl.db

# Objects to harvest: "fd" (files + directories), "d" (directories only), or "f" (files only)
scantype: fd

# Harvest effective NTFS (Windows) or POSIX (Linux/macOS) permissions
permissions: true

# Query Active Directory for group membership of discovered ACLs (Windows only)
crawl_acls: true

# Optional MD5 checksum limit in bytes (e.g. 10485760 = 10 MB); null disables MD5 hashing
max_md5: 10485760

# Optional caps for stepwise ("peeling away the layers") crawls; 0 = unlimited
limit: 0
max_depth: 0

# Scan supported file contents (.txt, .csv, .xlsx) for PII keywords
detect_pii: false
use_ner: false

# Automatically generate the multi-sheet Excel SOX & storage-cleanup summary report
# Written alongside `fout` as <fout_stem>_<YYYYMMDDTHHMMSS>.xlsx
summarize: true

# Optional standalone offline Plotly sunburst HTML output path
sunburst_html: finance_sunburst.html

# Resume an interrupted crawl (scan_end IS NULL in CRAWL_INFO) instead of starting over
resume: false

# Logging verbosity: ERROR, WARNING, INFO, DEBUG, TRACE
log_level: INFO

Example examples/report_config.yaml:

# Sample LANspector YAML configuration for `lanspector report`
#
# Usage:
#   lanspector report --config examples/report_config.yaml

# One or more LANspector SQLite crawl databases to summarize
databases:
  - finance_crawl.db

# Destination Excel audit workbook
output: finance_audit_report.xlsx

# Optional crawl timestamp table name (null = latest crawl)
table: null

# Row limit per detail worksheet (null or 0 = unlimited)
limit: 500

# Collapse subordinate permission bits (e.g. MR -> M; Full Control dominates lower grants)
use_permission_hierarchy: true

# Include or skip specific worksheets
skip_files_report: false
skip_user_owner_report: false
report_pii: true

# Generate an Open Shares rollup instead of a full fileshare audit workbook
open_shares: false

log_level: INFO

Batch Crawling with a Driver File#

Create a plain text driver file listing one target per line (blank lines and # comments are ignored):

# Local or UNC paths
\\filesrv01\finance
\\filesrv02\actuarial

# Fileserver hostname (Windows: crawls all non-admin shares)
filesrv03

# Domain discovery (Windows: enumerates domain computers and their shares)
DN: CORP

Then run:

lanspector crawl --driver shares.txt --driver_out ./crawls --summarize true

Stepwise “Peeling Away the Layers”#

On large fileshares, start with --limit 100 or --max_depth 2 to remediate share-level and top-level NTFS entitlements first, then progressively increase depth in subsequent crawls stored in the same SQLite database.