Skip to content

Commit be381f4

Browse files
committed
Update README.md with changes and with more examples
1 parent b71ea75 commit be381f4

File tree

1 file changed

+83
-6
lines changed

1 file changed

+83
-6
lines changed

README.md

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,19 @@
2424
## Usage
2525

2626
```bash
27-
mmdbinspect -db <path/to/your.mmdb> <IP|network>
28-
db Path to a MMDB file. Can be specified multiple times.
29-
<IP|network> An IP address, or network in CIDR notation. Can be
30-
specified multiple times.
27+
mmdbinspect [-include-aliased-networks] [-include-build-time] [-include-networks-without-data] [-jsonl] -db path/to/db [IP|network] [IP|network]...
28+
-db value Path to an mmdb file. You may pass this arg more than once.
29+
This may also be a glob pattern matching one or more MMDB files.
30+
-include-aliased-networks
31+
Include aliased networks (e.g. 6to4, Teredo). This option may
32+
cause IPv4 networks to be listed more than once via aliases.
33+
-include-build-time Include the build time of the database in the output.
34+
-include-networks-without-data
35+
Include networks that have no data in the database.
36+
The "record" will be null for these.
37+
-jsonl Output as JSONL instead of YAML.
38+
[IP|network] An IP address, or network in CIDR notation. Can be
39+
specified multiple times.
3140
```
3241

3342
## Description
@@ -36,7 +45,7 @@ Any IPs specified will be treated as their single-host network counterparts (e.g
3645

3746
`mmdbinspect` will look up each IP/network in each database specified. For each IP/network looked up in a database, the program will select all records for networks which are contained within the looked up IP/network. If no records for contained networks are found in the datafile, the program will select the record that is contained by the looked up IP/network. If no such records are found, none are selected.
3847

39-
The program outputs the selected records as a JSON array, with each item in the array corresponding to a single IP/network being looked up in a single DB. The `database` and `requested_lookup` keys are added to each item to help correlate which set of records resulted from looking up which IP/network in which database.
48+
The program outputs the selected records in YAML format by default (use `-jsonl` for JSONL format). Each output item corresponds to a single IP/network being looked up in a single DB. Each record contains the following keys: `database_path`, `requested_lookup`, `network`, and `record`. This format allows for efficient streaming of large lookups and makes the key naming more consistent.
4049

4150
## Beta Release
4251

@@ -283,6 +292,35 @@ record:
283292
```
284293
</details>
285294

295+
<details>
296+
<summary>Using glob patterns to match multiple database files</summary>
297+
298+
```bash
299+
$ mmdbinspect -db "GeoIP2-*.mmdb" 152.216.7.110
300+
database_path: GeoIP2-Country.mmdb
301+
requested_lookup: 152.216.7.110
302+
network: 152.208.0.0/12
303+
record:
304+
continent:
305+
code: NA
306+
geoname_id: 6255149
307+
names:
308+
de: Nordamerika
309+
en: North America
310+
# ... more names
311+
country:
312+
geoname_id: 6252001
313+
iso_code: US
314+
# ... more country data
315+
---
316+
database_path: GeoIP2-City.mmdb
317+
requested_lookup: 152.216.7.110
318+
network: 152.216.4.0/22
319+
record:
320+
# ... city data
321+
```
322+
</details>
323+
286324
<details>
287325
<summary>Look up a file of IPs/networks using the <code>xargs</code> utility</summary>
288326

@@ -312,7 +350,7 @@ record:
312350
</details>
313351

314352
<details>
315-
<summary>Tame the output with the <code>-jsonl</code> flag and the <code>jq</code> utility</summary>
353+
<summary>Processing the output with the <code>-jsonl</code> flag and the <code>jq</code> utility</summary>
316354

317355
Print out the `isp` field from each result found:
318356
```bash
@@ -344,6 +382,16 @@ $ mmdbinspect -jsonl -db GeoLite2-ASN.mmdb 152.216.7.49 | jq -r '.record.autonom
344382
30313
345383
```
346384

385+
Create a CSV file with network and country code for all networks:
386+
```bash
387+
$ echo "network,country" > networks.csv
388+
$ mmdbinspect -jsonl -db GeoIP2-Country.mmdb ::/0 | jq -r '[.network, .record.country.iso_code] | join(",")' >> networks.csv
389+
$ cat networks.csv
390+
network,country
391+
1.1.1.0/24,AU
392+
...
393+
```
394+
347395
When asking `jq` to print a path it can't find, it'll print `null`:
348396
```bash
349397
$ mmdbinspect -jsonl -db GeoIP2-City.mmdb 152.216.7.49 | jq -r '.invalid.path'
@@ -359,6 +407,35 @@ $ mmdbinspect -jsonl -db GeoIP2-City.mmdb 152.216.7.49 | jq -r '.record | [.city
359407
```
360408
</details>
361409

410+
<details>
411+
<summary>Using the `-include-*` flags for additional information</summary>
412+
413+
Include build time information:
414+
```bash
415+
$ mmdbinspect -db GeoIP2-City.mmdb -include-build-time 152.216.7.110
416+
database_path: GeoIP2-City.mmdb
417+
build_time: 2023-01-15T12:34:56Z
418+
requested_lookup: 152.216.7.110
419+
network: 152.216.4.0/22
420+
record:
421+
# ... city data
422+
```
423+
424+
Include networks without data:
425+
```bash
426+
$ mmdbinspect -db GeoIP2-City.mmdb -include-networks-without-data 192.0.2.1
427+
database_path: GeoIP2-City.mmdb
428+
requested_lookup: 192.0.2.1
429+
network: 192.0.2.0/24
430+
```
431+
432+
Include aliased networks:
433+
```bash
434+
$ mmdbinspect -db GeoIP2-City.mmdb -include-aliased-networks ::/0
435+
# ... All IPs in the database, including all aliased networks.
436+
```
437+
</details>
438+
362439
## Bug Reports
363440

364441
Please report bugs by filing an issue with our GitHub issue tracker at [https://github.com/maxmind/mmdbinspect/issues](https://github.com/maxmind/mmdbinspect/issues).

0 commit comments

Comments
 (0)