netriskscan-cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.0.0] - 2026-08-26
11
+
12
+ ### Added
13
+
14
+ - `netriskscan check <ip>` - query `GET /v1/ip-risk/{ip}`, with human, `--json`,
15
+ `--verbose`, `--fail-below`, and `--fail-on` output modes.
16
+ - `netriskscan usage` - query `GET /v1/usage`.
17
+ - `netriskscan batch <file>` - client-side batch over `GET /v1/ip-risk/{ip}` with
18
+ controlled concurrency, `--jsonl` output, and `-` for stdin.
19
+ - `NetRiskScanClient` SDK (`checkIp`, `getUsage`) with typed responses, automatic
20
+ retry on `429`/`503` honoring `Retry-After`, request timeouts, and `X-Request-Id`
21
+ support.
22
+ - Strict tri-state handling for `flags.*` (`true` / `false` / `null`) and for
23
+ `risk.index` (including `0` and `null`).
24
+ - Stable CLI exit codes (0-7), documented in the README.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NetRiskScan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,501 @@
1
+ # NetRiskScan CLI
2
+
3
+ Query IP risk, network intelligence and reputation data directly from your terminal.
4
+
5
+ Powered by the [NetRiskScan Developer API](#developer-api).
6
+
7
+ [![CI](https://github.com/TeamQQ/netriskscan-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/TeamQQ/netriskscan-cli/actions/workflows/ci.yml)
8
+ [![npm version](https://img.shields.io/npm/v/netriskscan-cli.svg)](https://www.npmjs.com/package/netriskscan-cli)
9
+ [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
10
+
11
+ ```bash
12
+ npm install -g netriskscan-cli
13
+ ```
14
+
15
+ ```bash
16
+ export NETRISKSCAN_API_KEY="nrs_live_xxx"
17
+
18
+ netriskscan check 1.1.1.1
19
+ ```
20
+
21
+ > NetRiskScan provides diagnostic network intelligence. Results should not be treated as
22
+ > proof of malicious activity and should not be used as the sole basis for legal,
23
+ > employment, credit, identity, or other high-impact decisions.
24
+
25
+ ## Table of contents
26
+
27
+ - [Introduction](#introduction)
28
+ - [Features](#features)
29
+ - [Installation](#installation)
30
+ - [Getting an API key](#getting-an-api-key)
31
+ - [Quick start](#quick-start)
32
+ - [IP risk check](#ip-risk-check)
33
+ - [Usage & quota](#usage--quota)
34
+ - [Batch processing](#batch-processing)
35
+ - [JSON output](#json-output)
36
+ - [JSONL output](#jsonl-output)
37
+ - [CI/CD](#cicd)
38
+ - [Environment variables](#environment-variables)
39
+ - [Exit codes](#exit-codes)
40
+ - [API errors](#api-errors)
41
+ - [Rate limits & quota](#rate-limits--quota)
42
+ - [SDK usage](#sdk-usage)
43
+ - [Security](#security)
44
+ - [Developer API](#developer-api)
45
+ - [Contributing](#contributing)
46
+ - [License](#license)
47
+
48
+ ## Introduction
49
+
50
+ `netriskscan-cli` is the official command-line client (and thin SDK) for the
51
+ [NetRiskScan](https://www.netriskscan.com) Developer API - an automated IP risk and
52
+ network intelligence lookup service. Give it an IP address, get back a machine-readable
53
+ reputation score, network attribution, and risk signals.
54
+
55
+ This is a read-only diagnostic tool. It does not make decisions for you, and the CLI
56
+ never recomputes or approximates a risk score client-side - the `risk.index` returned by
57
+ the server is always the single source of truth.
58
+
59
+ ## Features
60
+
61
+ - `check`, `usage`, and client-side `batch` commands
62
+ - IPv4 and IPv6 support
63
+ - Human-readable terminal output, `--json`, and `--jsonl` (batch) modes
64
+ - Correct three-state handling of risk flags (`true` / `false` / `null` - never coerced)
65
+ - CI-friendly exit codes and `--fail-below` / `--fail-on` policy gates
66
+ - Automatic retry with backoff on `429` / `503`, respecting `Retry-After`
67
+ - Rate limit and quota visibility via `--verbose`
68
+ - Zero telemetry
69
+ - A typed `NetRiskScanClient` SDK you can import directly in Node.js/TypeScript
70
+
71
+ ## Installation
72
+
73
+ ```bash
74
+ npm install -g netriskscan-cli
75
+ ```
76
+
77
+ Or run it without a global install:
78
+
79
+ ```bash
80
+ npx netriskscan-cli check 1.1.1.1
81
+ ```
82
+
83
+ Requires Node.js >= 20.
84
+
85
+ ## Getting an API key
86
+
87
+ 1. Create a NetRiskScan Developer account and open the **Developer Dashboard**.
88
+ 2. Go to **API Keys** and create one, selecting the scopes you need
89
+ (`ip-risk:read`, `usage:read`).
90
+ 3. Copy the full key immediately - it is shown in full only once, right after creation.
91
+
92
+ A NetRiskScan Developer account includes a **Free Plan** (no credit card required), so
93
+ you can try the real API with real data before committing to a paid plan. Current
94
+ pricing, rate limits, quotas, and concurrency limits are shown on the Developer
95
+ Dashboard's **Pricing** and **Usage** pages and are not duplicated here, since they
96
+ change over time.
97
+
98
+ Store your key in an environment variable rather than typing it inline (inline values
99
+ can end up in your shell history):
100
+
101
+ ```bash
102
+ export NETRISKSCAN_API_KEY="nrs_live_xxx"
103
+ ```
104
+
105
+ ## Quick start
106
+
107
+ ```bash
108
+ export NETRISKSCAN_API_KEY="nrs_live_xxx"
109
+
110
+ netriskscan check 1.1.1.1
111
+ netriskscan usage
112
+ netriskscan batch ips.txt --jsonl > results.jsonl
113
+ ```
114
+
115
+ ## IP risk check
116
+
117
+ ```bash
118
+ netriskscan check <ip> [options]
119
+ ```
120
+
121
+ Calls `GET /v1/ip-risk/{ip}` - no query string parameters are ever sent.
122
+
123
+ ```bash
124
+ $ netriskscan check 1.1.1.1
125
+
126
+ NetRiskScan
127
+
128
+ IP 1.1.1.1
129
+ Index 92
130
+ Band excellent
131
+ Assessment complete
132
+
133
+ Network
134
+ Type public_infrastructure
135
+ Connection direct
136
+ ASN AS13335
137
+ Organization Cloudflare, Inc.
138
+
139
+ Signals
140
+ Proxy No
141
+ VPN No
142
+ Tor No
143
+ Datacenter Unknown
144
+ Scanner No
145
+ Abuse No
146
+
147
+ Request ID req_xxxxxxxx
148
+ ```
149
+
150
+ Output above is illustrative of the format - actual values always come from the live
151
+ API response.
152
+
153
+ ### Addresses that can't be scored
154
+
155
+ Private, loopback, reserved, and other non-routable addresses still return `HTTP 200`,
156
+ but with `risk.assessmentGrade: "insufficient"` and `risk.index` / `risk.band` set to
157
+ `null`. The CLI shows this as:
158
+
159
+ ```text
160
+ Index N/A
161
+ Band N/A
162
+ Assessment insufficient
163
+
164
+ This address could not be reliably assessed.
165
+ ```
166
+
167
+ This is a normal, successful response - the CLI's default exit code stays `0` unless
168
+ you opt into CI policy checks with `--fail-below` (see [CI/CD](#cicd)).
169
+
170
+ ### Options
171
+
172
+ | Option | Description |
173
+ | --- | --- |
174
+ | `--api-key <key>` | API key for this call (overrides `NETRISKSCAN_API_KEY`) |
175
+ | `--base-url <url>` | Override the API base URL (advanced) |
176
+ | `--json` | Machine-readable JSON output (see [JSON output](#json-output)) |
177
+ | `--verbose` | Also print rate limit, quota, and request id |
178
+ | `--debug` | Print a stack trace / extra detail on failure |
179
+ | `--timeout <ms>` | Request timeout in milliseconds (default `10000`) |
180
+ | `--max-retries <n>` | Max automatic retries for `429`/`503` (default `3`) |
181
+ | `--fail-below <index>` | CI gate: exit non-zero if `risk.index` is below this threshold |
182
+ | `--fail-on <flag>` | CI gate: exit non-zero if the given flag is `true` (repeatable) |
183
+
184
+ ## Usage & quota
185
+
186
+ ```bash
187
+ netriskscan usage
188
+ ```
189
+
190
+ Calls `GET /v1/usage` (requires the `usage:read` scope).
191
+
192
+ ```bash
193
+ $ netriskscan usage
194
+
195
+ NetRiskScan Usage
196
+
197
+ Plan growth
198
+
199
+ Usage
200
+ Used 12,450
201
+ Remaining 37,550
202
+ Limit 50,000
203
+
204
+ Rate limit
205
+ Requests / minute 120
206
+
207
+ Billing period
208
+ 2026-08-01 → 2026-09-01
209
+ ```
210
+
211
+ Supports `--json`, `--verbose`, `--api-key`, `--timeout`, and `--max-retries` just like
212
+ `check`.
213
+
214
+ ## Batch processing
215
+
216
+ ```bash
217
+ netriskscan batch <file> [options]
218
+ ```
219
+
220
+ **Important:** NetRiskScan does not currently expose a server-side batch endpoint. This
221
+ command is a **client-side batch**: it sends individual `GET /v1/ip-risk/{ip}` requests
222
+ with a controlled concurrency limit. It never calls `/v1/ip-risk/batch` or
223
+ `/v1/ip-risk/query` - those endpoints are not open and currently return
224
+ `404 feature_not_available`.
225
+
226
+ Input is one IP per line; blank lines and lines starting with `#` are ignored:
227
+
228
+ ```text
229
+ # ips.txt
230
+ 1.1.1.1
231
+ 8.8.8.8
232
+ 9.9.9.9
233
+ 2606:4700:4700::1111
234
+ ```
235
+
236
+ ```bash
237
+ netriskscan batch ips.txt
238
+ cat ips.txt | netriskscan batch -
239
+ netriskscan batch ips.txt --concurrency 10 --jsonl > results.jsonl
240
+ ```
241
+
242
+ ### Concurrency
243
+
244
+ ```bash
245
+ netriskscan batch ips.txt --concurrency 5 # default
246
+ netriskscan batch ips.txt --concurrency 10
247
+ ```
248
+
249
+ Concurrency defaults to a conservative `5` and is capped at `20` regardless of what you
250
+ pass - it is never unbounded. Make sure the concurrency you choose complies with the
251
+ limits shown in your NetRiskScan Developer Dashboard for your plan.
252
+
253
+ A failure on one IP never drops the others - every input line gets a result.
254
+
255
+ ### Options
256
+
257
+ | Option | Description |
258
+ | --- | --- |
259
+ | `--api-key <key>` | API key for this run (overrides `NETRISKSCAN_API_KEY`) |
260
+ | `--base-url <url>` | Override the API base URL (advanced) |
261
+ | `--concurrency <n>` | Concurrent requests (default `5`, max `20`) |
262
+ | `--jsonl` | Newline-delimited JSON output (see [JSONL output](#jsonl-output)) |
263
+ | `--timeout <ms>` | Per-request timeout in milliseconds (default `10000`) |
264
+ | `--max-retries <n>` | Max automatic retries per request for `429`/`503` (default `3`) |
265
+
266
+ ## JSON output
267
+
268
+ ```bash
269
+ netriskscan check 1.1.1.1 --json
270
+ ```
271
+
272
+ Prints exactly the API response body as JSON, with `null` preserved as `null` (never
273
+ coerced to `false`, `0`, or a string):
274
+
275
+ ```json
276
+ {
277
+ "requestId": "req_8f3ab21c9d",
278
+ "risk": { "index": 72, "band": "good", "assessmentGrade": "complete" },
279
+ "network": { "type": "residential", "connectionType": "isp", "asn": "AS4134", "organization": "China Telecom" },
280
+ "flags": { "proxy": false, "vpn": false, "tor": false, "datacenter": false, "scanner": false, "abuse": false }
281
+ }
282
+ ```
283
+
284
+ In `--json` mode there is no spinner, no ANSI color, and no banner - stdout carries only
285
+ the JSON. Errors always go to stderr, so this composes cleanly:
286
+
287
+ ```bash
288
+ netriskscan check 1.1.1.1 --json | jq '.risk.index'
289
+ ```
290
+
291
+ ## JSONL output
292
+
293
+ ```bash
294
+ netriskscan batch ips.txt --jsonl
295
+ ```
296
+
297
+ One JSON object per line, one line per input IP:
298
+
299
+ ```json
300
+ {"ip":"1.1.1.1","ok":true,"result":{"requestId":"req_...","risk":{...},"network":{...},"flags":{...}}}
301
+ {"ip":"8.8.8.8","ok":true,"result":{...}}
302
+ {"ip":"bad-ip","ok":false,"error":{"code":"invalid_ip","message":"..."}}
303
+ ```
304
+
305
+ Designed for `netriskscan batch ips.txt --jsonl > results.jsonl` and downstream
306
+ line-oriented processing (`jq`, `grep`, log pipelines, etc.). A failed IP never causes
307
+ the whole batch to fail or drops output for the rest.
308
+
309
+ ## CI/CD
310
+
311
+ Use `check` with policy flags as a build/deploy gate:
312
+
313
+ ```bash
314
+ netriskscan check "$TARGET_IP" --fail-below 60
315
+ netriskscan check "$TARGET_IP" --fail-on tor --fail-on proxy
316
+ ```
317
+
318
+ Rules:
319
+
320
+ - `risk.index >= threshold` → exit `0`
321
+ - `risk.index < threshold` → exit `6` (CI policy failed)
322
+ - `risk.index == null` (address could not be assessed) → exit `7`, a distinct code from
323
+ a normal policy failure
324
+ - `--fail-on <flag>` only trips on an explicit `true`. A `null` (unknown) value is never
325
+ treated as a hit - that would silently turn "we don't know" into "blocked".
326
+
327
+ ## Environment variables
328
+
329
+ | Variable | Description |
330
+ | --- | --- |
331
+ | `NETRISKSCAN_API_KEY` | Default API key, used when `--api-key` is not passed |
332
+ | `NETRISKSCAN_BASE_URL` | Advanced: override the API base URL, used when `--base-url` is not passed |
333
+
334
+ ## Exit codes
335
+
336
+ | Code | Meaning |
337
+ | --- | --- |
338
+ | `0` | Success |
339
+ | `1` | General CLI error |
340
+ | `2` | Invalid CLI argument |
341
+ | `3` | Authentication / authorization failure |
342
+ | `4` | API request failure |
343
+ | `5` | Rate limit / quota exceeded |
344
+ | `6` | CI policy failed (`--fail-below` / `--fail-on`) |
345
+ | `7` | Assessment unavailable (`--fail-below` used against a `null` index) |
346
+
347
+ These codes are stable and part of the CLI's public contract.
348
+
349
+ ## API errors
350
+
351
+ The API returns a consistent error shape:
352
+
353
+ ```json
354
+ {
355
+ "error": {
356
+ "code": "quota_exceeded",
357
+ "message": "Billing period quota exhausted.",
358
+ "requestId": "req_8f3ab21c9d"
359
+ }
360
+ }
361
+ ```
362
+
363
+ The CLI prints this as:
364
+
365
+ ```text
366
+ NetRiskScan API error
367
+
368
+ Code quota_exceeded
369
+ Status 429
370
+ Message Billing period quota exhausted.
371
+ Request ID req_8f3ab21c9d
372
+ ```
373
+
374
+ Known error codes:
375
+
376
+ | HTTP status | `error.code` | Meaning |
377
+ | --- | --- | --- |
378
+ | 400 | `invalid_ip` | The address is not a valid IPv4/IPv6 address |
379
+ | 400 | `invalid_request` | Unsupported query parameter, or request too large |
380
+ | 400 | `unsupported_parameter` | e.g. `forceRefresh` / `force_refresh` / `refresh` - not supported |
381
+ | 401 | `invalid_api_key` | Missing/malformed `Authorization` header, or key doesn't exist |
382
+ | 403 | `api_key_disabled` | Key revoked/expired, or account/plan unavailable |
383
+ | 403 | `scope_not_allowed` | Key lacks the scope required for this endpoint |
384
+ | 404 | `not_found` | Unknown path |
385
+ | 404 | `feature_not_available` | Endpoint not yet available (e.g. batch, see above) |
386
+ | 429 | `rate_limit_exceeded` | Per-minute request limit exceeded |
387
+ | 429 | `quota_exceeded` | Billing-period quota exhausted |
388
+ | 503 | `temporarily_unavailable` | Transient upstream/service issue - retry later |
389
+
390
+ Only `429` and `503` are retried automatically, honoring `Retry-After` when present and
391
+ falling back to exponential backoff with jitter otherwise. `400` / `401` / `403` / `404`
392
+ are never retried automatically.
393
+
394
+ Pass `--debug` to any command to include a stack trace on failure. Without it, errors
395
+ are shown as a clean summary - never a raw stack dump.
396
+
397
+ ## Rate limits & quota
398
+
399
+ Every successful `/v1/*` response carries live rate limit and quota headers, so you
400
+ don't need a separate call to `/v1/usage` to know where you stand:
401
+
402
+ | Header | Meaning |
403
+ | --- | --- |
404
+ | `X-RateLimit-Limit` / `X-RateLimit-Remaining` / `X-RateLimit-Reset` | Per-minute limit |
405
+ | `X-Quota-Limit` / `X-Quota-Used` / `X-Quota-Remaining` | Billing-period quota |
406
+ | `X-Request-Id` | Request trace id (echoes yours, or a generated one) |
407
+ | `Retry-After` | Present on `429` responses |
408
+
409
+ See them with:
410
+
411
+ ```bash
412
+ netriskscan check 1.1.1.1 --verbose
413
+ ```
414
+
415
+ ```text
416
+ Rate limit 118 / 120 remaining
417
+ Quota 37,550 / 50,000 remaining
418
+ Request ID req_xxxxxxxx
419
+ ```
420
+
421
+ ## SDK usage
422
+
423
+ The API client is a standalone module, independent of the CLI layer, so it can be used
424
+ directly from Node.js/TypeScript and will move to `@netriskscan/sdk` in a future release
425
+ without changing its shape:
426
+
427
+ ```ts
428
+ import { NetRiskScanClient, NetRiskScanApiError } from "netriskscan-cli";
429
+
430
+ const client = new NetRiskScanClient({
431
+ apiKey: process.env.NETRISKSCAN_API_KEY!,
432
+ timeout: 10000,
433
+ maxRetries: 3,
434
+ });
435
+
436
+ try {
437
+ const { data, meta } = await client.checkIp("1.1.1.1");
438
+ console.log(data.risk.index, data.risk.band, data.flags.vpn);
439
+ console.log(meta.rateLimit.remaining, meta.quota.remaining);
440
+ } catch (err) {
441
+ if (err instanceof NetRiskScanApiError) {
442
+ console.error(`${err.code}: ${err.message} (requestId=${err.requestId})`);
443
+ } else {
444
+ throw err;
445
+ }
446
+ }
447
+ ```
448
+
449
+ ```ts
450
+ const usage = await client.getUsage();
451
+ console.log(usage.data.units.remaining);
452
+ ```
453
+
454
+ See [examples/](examples/) for runnable scripts.
455
+
456
+ ## Security
457
+
458
+ - The CLI never prints, logs, or includes a full API key in error output or telemetry.
459
+ - There is no telemetry: **the CLI does not collect usage analytics or telemetry** of any
460
+ kind, in any version.
461
+ - If `--debug` needs to show an authorization value, it is redacted
462
+ (`Bearer nrs_live_abcd****1234`) - never printed in full.
463
+ - Prefer `export NETRISKSCAN_API_KEY=...` over passing `--api-key` inline, to keep the
464
+ key out of shell history and process listings where practical.
465
+ - See [SECURITY.md](SECURITY.md) for how to report vulnerabilities and what to do if a
466
+ key leaks.
467
+
468
+ ## Developer API
469
+
470
+ | | |
471
+ | --- | --- |
472
+ | Base URL | `https://api.netriskscan.com` |
473
+ | Current version | `v1` (path prefix `/v1`, **not** `/api/v1`) |
474
+
475
+ This is a completely separate system from the netriskscan.com website's internal
476
+ `/api/public/*` endpoints - different auth, different response shapes, no compatibility
477
+ guarantees between the two. `netriskscan-cli` only ever calls `/v1/*`.
478
+
479
+ Currently available endpoints:
480
+
481
+ - `GET /v1/ip-risk/{ip}` - requires `ip-risk:read`
482
+ - `GET /v1/usage` - requires `usage:read`
483
+
484
+ There is currently **no** server-side batch, history, or key-management endpoint
485
+ (`POST /v1/ip-risk/batch`, `POST /v1/ip-risk/query`, `GET /v1/history`,
486
+ `GET|POST /v1/key`, etc. are not implemented). API key creation/rotation/revocation is
487
+ only available through the Developer Dashboard.
488
+
489
+ `/v1/*` never accepts query string parameters - all inputs are path parameters.
490
+
491
+ See the official [Methodology](https://www.netriskscan.com/methodology.html) page for
492
+ how the NetRiskScan Index itself is computed (this project does not - and will not -
493
+ reimplement that logic client-side).
494
+
495
+ ## Contributing
496
+
497
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
498
+
499
+ ## License
500
+
501
+ [MIT](LICENSE)