• Stars
    star
    114
  • Rank 298,054 (Top 7 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

look up records for one or more IPs/networks in one or more .mmdb databases

mmdbinspect

mmdbinspect - look up records for one or more IPs/networks in one or more .mmdb databases

Build Status Coverage Status

Usage

mmdbinspect -db <path/to/your.mmdb> <IP|network>
  db            Path to a MMDB file. Can be specified multiple times.
  <IP|network>  An IP address, or network in CIDR notation. Can be
                specified multiple times.

Description

Any IPs specified will be treated as their single-host network counterparts (e.g. 1.2.3.4 => 1.2.3.4/32).

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.

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 Lookup keys are added to each item to help correlate which set of records resulted from looking up which IP/network in which database.

Beta Release

This software is in beta. No guarantees are made, including relating to interface stability. Comments or suggestions for improvements are welcome on our GitHub issue tracker.

Installation

Installing via binary release

Release binaries have been made available for several popular platforms. Simply download the binary for your platform and run it.

Installing on Linux via the tarball

Download and extract the appropriate tarball for your system. You will end up with a directory named something like mmdbinspect_0.0.0_linux_amd64 depending on the version and architecture.

Copy mmdbinspect to where you want it to live. To install it into /usr/local/bin/mmdbinspect, run the equivalent of sudo cp mmdbinspect_0.0.0_linux_amd64/mmdbinspect /usr/local/bin.

Installing on Ubuntu or Debian via the .deb

(N.B. You can also use the tarball.)

Download the appropriate .deb for your system.

Run dpkg -i path/to/mmdbinspect_0.0.0_linux_amd64.deb (replacing the version number and architecture as necessary). You will need to be root. For Ubuntu you can prefix the command with sudo. This will install mmdbinspect to /usr/bin/mmdbinspect.

Installing on RedHat or CentOS via the rpm

(N.B. You can also use the tarball.)

Run rpm -i path/to/mmdbinspect_0.0.0_linux_amd64.rpm (replacing the version number and architecture as necessary). You will need to be root. This will install mmdbinspect to /usr/bin/mmdbinspect.

Installing on macOS (darwin) via the tarball

This is the same as installing on Linux via the tarball, except choose a tarball with "darwin" in the name.

Installing on Windows

Download and extract the appropriate zip for your system. You will end up with a directory named something like mmdbinspect_0.0.0_windows_amd64 depending on the version and architecture.

Copy mmdbinspect.exe to where you want it to live.

Installing from source or Git

We aim always to support the current and penultimate major releases of the Go compiler. You can get it at the Go website.

The easiest way is via go install:

$ go install github.com/maxmind/mmdbinspect/cmd/mmdbinspect@latest

This installs mmdbinspect to $GOPATH/bin/mmdbinspect.

Examples

A simple lookup (one IP/network, one DB)
$ mmdbinspect -db GeoIP2-Country.mmdb 152.216.7.110
[
    {
        "Database": "GeoIP2-Country.mmdb",
        "Records": [
            {
                "Network": "152.216.7.110/12",
                "Record": {
                    "continent": {
                        "code": "NA",
                        "geoname_id": 6255149,
                        "names": {
                            "de": "Nordamerika",
                            "en": "North America",
                            "es": "Norteamérica",
                            "fr": "Amérique du Nord",
                            "ja": "北アメリカ",
                            "pt-BR": "América do Norte",
                            "ru": "Северная Америка",
                            "zh-CN": "北美洲"
                        }
                    },
                    "country": {
                        "geoname_id": 6252001,
                        "iso_code": "US",
                        "names": {
                            "de": "USA",
                            "en": "United States",
                            "es": "Estados Unidos",
                            "fr": "États-Unis",
                            "ja": "アメリカ合衆国",
                            "pt-BR": "Estados Unidos",
                            "ru": "США",
                            "zh-CN": "美国"
                        }
                    },
                    "registered_country": {
                        "geoname_id": 6252001,
                        "iso_code": "US",
                        "names": {
                            "de": "USA",
                            "en": "United States",
                            "es": "Estados Unidos",
                            "fr": "États-Unis",
                            "ja": "アメリカ合衆国",
                            "pt-BR": "Estados Unidos",
                            "ru": "США",
                            "zh-CN": "美国"
                        }
                    }
                }
            }
        ],
        "Lookup": "152.216.7.110"
    }
]
Look up one IP/network in multiple databases
$ mmdbinspect -db GeoIP2-Country.mmdb -db GeoIP2-City.mmdb 152.216.7.110
[
    {
        "Database": "GeoIP2-Country.mmdb",
        "Records": [
            {
                "Network": "152.216.7.110/12",
                "Record": {
                    "continent": {
                        "code": "NA",
                        "geoname_id": 6255149,
                        "names": {
                            "de": "Nordamerika",
                            "en": "North America",
                            "es": "Norteamérica",
                            "fr": "Amérique du Nord",
                            "ja": "北アメリカ",
                            "pt-BR": "América do Norte",
                            "ru": "Северная Америка",
                            "zh-CN": "北美洲"
                        }
                    },
                    "country": {
                        "geoname_id": 6252001,
                        "iso_code": "US",
                        "names": {
                            "de": "USA",
                            "en": "United States",
                            "es": "Estados Unidos",
                            "fr": "États-Unis",
                            "ja": "アメリカ合衆国",
                            "pt-BR": "Estados Unidos",
                            "ru": "США",
                            "zh-CN": "美国"
                        }
                    },
                    "registered_country": {
                        "geoname_id": 6252001,
                        "iso_code": "US",
                        "names": {
                            "de": "USA",
                            "en": "United States",
                            "es": "Estados Unidos",
                            "fr": "États-Unis",
                            "ja": "アメリカ合衆国",
                            "pt-BR": "Estados Unidos",
                            "ru": "США",
                            "zh-CN": "美国"
                        }
                    }
                }
            }
        ],
        "Lookup": "152.216.7.110"
    },
    {
        "Database": "GeoIP2-City.mmdb",
        "Records": [
            {
                "Network": "152.216.7.110/14",
                "Record": {
                    "continent": {
                        "code": "NA",
                        "geoname_id": 6255149,
                        "names": {
                            "de": "Nordamerika",
                            "en": "North America",
                            "es": "Norteamérica",
                            "fr": "Amérique du Nord",
                            "ja": "北アメリカ",
                            "pt-BR": "América do Norte",
                            "ru": "Северная Америка",
                            "zh-CN": "北美洲"
                        }
                    },
                    "country": {
                        "geoname_id": 6252001,
                        "iso_code": "US",
                        "names": {
                            "de": "USA",
                            "en": "United States",
                            "es": "Estados Unidos",
                            "fr": "États-Unis",
                            "ja": "アメリカ合衆国",
                            "pt-BR": "Estados Unidos",
                            "ru": "США",
                            "zh-CN": "美国"
                        }
                    },
                    "location": {
                        "accuracy_radius": 1000,
                        "latitude": 37.751,
                        "longitude": -97.822,
                        "time_zone": "America/Chicago"
                    },
                    "registered_country": {
                        "geoname_id": 6252001,
                        "iso_code": "US",
                        "names": {
                            "de": "USA",
                            "en": "United States",
                            "es": "Estados Unidos",
                            "fr": "États-Unis",
                            "ja": "アメリカ合衆国",
                            "pt-BR": "Estados Unidos",
                            "ru": "США",
                            "zh-CN": "美国"
                        }
                    }
                }
            }
        ],
        "Lookup": "152.216.7.110"
    }
]
Look up multiple IPs/networks in a single database
$ mmdbinspect -db GeoIP2-Connection-Type.mmdb 152.216.7.110/20 2001:0:98d8::/64
[
    {
        "Database": "GeoIP2-Connection-Type.mmdb",
        "Records": [
            {
                "Network": "152.216.0.0/13",
                "Record": {
                    "connection_type": "Corporate"
                }
            }
        ],
        "Lookup": "152.216.7.110/20"
    },
    {
        "Database": "GeoIP2-Connection-Type.mmdb",
        "Records": [
            {
                "Network": "2001:0:98d8::/45",
                "Record": {
                    "connection_type": "Corporate"
                }
            }
        ],
        "Lookup": "2001:0:98d8::/64"
    }
]
Look up multiple IPs/networks in multiple databases
$ mmdbinspect -db GeoIP2-DensityIncome.mmdb -db GeoIP2-User-Count.mmdb 152.216.7.32/27 2610:30::/64
[
    {
        "Database": "GeoIP2-DensityIncome.mmdb",
        "Records": [
            {
                "Network": "152.216.7.32/21",
                "Record": {
                    "average_income": 26483,
                    "population_density": 1265
                }
            }
        ],
        "Lookup": "152.216.7.32/27"
    },
    {
        "Database": "GeoIP2-DensityIncome.mmdb",
        "Records": [
            {
                "Network": "2610:30::/38",
                "Record": {
                    "average_income": 30369,
                    "population_density": 934
                }
            }
        ],
        "Lookup": "2610:30::/64"
    },
    {
        "Database": "GeoIP2-User-Count.mmdb",
        "Records": [
            {
                "Network": "152.216.7.32/27",
                "Record": {
                    "ipv4_24": 6,
                    "ipv4_32": 0
                }
            }
        ],
        "Lookup": "152.216.7.32/27"
    },
    {
        "Database": "GeoIP2-User-Count.mmdb",
        "Records": [
            {
                "Network": "2610:30::/27",
                "Record": {
                    "ipv6_32": 0,
                    "ipv6_48": 0,
                    "ipv6_64": 0
                }
            }
        ],
        "Lookup": "2610:30::/64"
    }
]
Look up a file of IPs/networks using the xargs utility
$ cat list.txt
152.216.7.32/27
2610:30::/64
$ cat list.txt | xargs mmdbinspect -db GeoIP2-ISP.mmdb
[
    {
        "Database": "/usr/local/share/GeoIP/GeoIP2-ISP.mmdb",
        "Records": [
            {
                "Network": "152.216.7.32/20",
                "Record": {
                    "autonomous_system_number": 30313,
                    "autonomous_system_organization": "IRS",
                    "isp": "Internal Revenue Service",
                    "organization": "Internal Revenue Service"
                }
            }
        ],
        "Lookup": "152.216.7.32/27"
    },
    {
        "Database": "/usr/local/share/GeoIP/GeoIP2-ISP.mmdb",
        "Records": [
            {
                "Network": "2610:30::/32",
                "Record": {
                    "autonomous_system_number": 30313,
                    "autonomous_system_organization": "IRS",
                    "isp": "Internal Revenue Service",
                    "organization": "Internal Revenue Service"
                }
            }
        ],
        "Lookup": "2610:30::/64"
    }
]
Tame the output with the jq utility

Print out the isp field from each result found:

$ mmdbinspect -db GeoIP2-ISP.mmdb 152.216.7.32/27 | jq -r '.[].Records[].Record.isp'
Internal Revenue Service

Print out the isp field from each result found in a specific format using string addition:

$ mmdbinspect -db GeoIP2-ISP.mmdb 152.216.7.32/27 | jq -r '.[].Records[].Record | "isp=" + .isp'
isp=Internal Revenue Service

Print out the city and country names from each record using string addition:

$ mmdbinspect -db GeoIP2-City.mmdb 2610:30::/64 | jq -r '.[].Records[].Record | .city.names.en + ", " + .country.names.en'
Martinsburg, United States

Print out the city and country names from each record using array construction and join:

$ mmdbinspect -db GeoIP2-City.mmdb 2610:30::/64 | jq -r '.[].Records[].Record | [.city.names.en, .country.names.en] | join(", ")'
Martinsburg, United States

Get the AS number for an IP:

$ mmdbinspect -db GeoLite2-ASN.mmdb 152.216.7.49 | jq -r '.[].Records[].Record.autonomous_system_number'
30313

When asking jq to print a path it can't find, it'll print null:

$ mmdbinspect -db GeoIP2-City.mmdb 152.216.7.49 | jq -r '.[].invalid.path'
null

When asking jq to concatenate or join a path it can't find, it'll leave it blank:

$ mmdbinspect -db GeoIP2-City.mmdb 152.216.7.49 | jq -r '.[].Records[].Record | .city.names.en + ", " + .country.names.en'
, United States
$ mmdbinspect -db GeoIP2-City.mmdb 152.216.7.49 | jq -r '.[].Records[].Record | [.city.names.en, .country.names.en] | join(", ")'
, United States

Bug Reports

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

Copyright and License

This software is Copyright (c) 2019 - 2021 by MaxMind, Inc.

This is free software, licensed under the Apache License, Version 2.0 or the MIT License, at your option.

More Repositories

1

GeoIP2-php

PHP API for GeoIP2 webservice client and database reader
PHP
2,279
star
2

GeoIP2-python

Python code for GeoIP2 webservice client and database reader
Python
1,067
star
3

libmaxminddb

C library for the MaxMind DB file format
C
875
star
4

GeoIP2-java

Java API for GeoIP2 webservice client and database reader
Java
748
star
5

geoipupdate

GeoIP update client code
Go
669
star
6

MaxMind-DB-Reader-php

PHP Reader for the MaxMind DB Database Format
PHP
632
star
7

geoip-api-php

DEPRECATED GeoIP Legacy PHP API
PHP
523
star
8

geoip-api-c

DEPRECATED GeoIP Legacy C API
C
369
star
9

GeoIP2-dotnet

MaxMind GeoIP2 .NET API
C#
331
star
10

web-service-common-php

Shared code for the MaxMind Web Service PHP client APIs
PHP
283
star
11

MaxMind-DB

Spec and test data for the MaxMind DB file format
Go
266
star
12

geoipupdate-legacy

GeoIP update client code
C
258
star
13

geoip-api-python

DEPRECATED GeoIP Legacy Python API
C
233
star
14

GeoIP2-node

Node.js API for GeoIP2 webservice client and database reader
TypeScript
205
star
15

geoip2-csv-converter

GeoIP2 CSV Format Converter
Go
198
star
16

geoip-api-java

DEPRECATED GeoIP Legacy Java API
Java
176
star
17

MaxMind-DB-Reader-python

Python MaxMind DB reader extension
Python
173
star
18

mod_maxminddb

MaxMind DB Apache Module
C
123
star
19

MaxMind-DB-Reader-java

Java reader for the MaxMind DB format
Java
109
star
20

mmdbwriter

Go library for writing MaxMind DB (mmdb) files
Go
100
star
21

MaxMind-DB-Reader-dotnet

.NET Reader for the MaxMind DB Database Format
C#
98
star
22

MaxMind-DB-Writer-perl

Create MaxMind DB database files
Perl
74
star
23

GeoIP2-ruby

Ruby API for GeoIP2 webservice client and database reader
Ruby
55
star
24

minfraud-api-php

PHP API for minFraud Score, Insights, and Factors
PHP
49
star
25

geoip-api-mod_geoip2

DEPRECATED GeoIP Legacy module for Apache 2
C
48
star
26

geoip-api-csharp2

DEPRECATED GeoIP Legacy C# API
C#
47
star
27

MaxMind-DB-Reader-ruby

Ruby reader for the MaxMind DB Database Format
Ruby
45
star
28

getting-started-with-mmdb

A quick guide to writing and reading from your own MMDB databases.
Perl
37
star
29

minfraud-api-python

Python API for minFraud Score, Insights, and Factors
Python
27
star
30

mmdb-from-go-blogpost

Enriching MMDB files with your own data using Go.
Go
23
star
31

ccfd-api-php

Deprecated minFraud Legacy PHP API
PHP
23
star
32

minfraud-api-dotnet

.NET API for MaxMind minFraud Score, Insights, and Factors
C#
19
star
33

GeoIP2-perl

Perl API for MaxMind's GeoIP2 web services and databases
Perl
18
star
34

minfraud-api-java

Java API for minFraud Score, Insights, and Factors
Java
18
star
35

minfraud-api-ruby

Ruby API for minFraud Score, Insights, and Factors
Ruby
14
star
36

mm-geofeed-verifier

Verify the format of a geofeed file, and make some comparisons to data in an MMDB file.
Go
14
star
37

dev-hire-homework

A homework exercise for engineering applicants
Perl
13
star
38

minfraud-api-node

Node.js API for MaxMind minFraud Score, Insights, and Factors
TypeScript
13
star
39

mm-network-analyzer

A program to aid in diagnosing networking issues
Go
12
star
40

MaxMind-DB-Reader-perl

Read MaxMind DB files and look up IP addresses
Perl
12
star
41

mmdbverify

Verifier for the MaxMind DB format
Go
10
star
42

geoip-api-perl

DEPRECATED GeoIP Legacy Perl API
Perl
10
star
43

Stepford

A vaguely Rake/Make/Cake-like thing for Perl - create steps and let a runner run them
Perl
9
star
44

Locale-Country-Multilingual

mapping ISO codes to localized country names
Perl
7
star
45

ccfd-api-java

Deprecated minFraud Legacy Java API
Java
7
star
46

Database-Migrator

Mirror of Database-Migrator on urth.org
Perl
5
star
47

Net-Works

Sane APIs for IP addresses and networks
Perl
5
star
48

MaxMind-DB-Reader-XS

Fast XS implementation of MaxMind DB reader
Perl
5
star
49

ccfd-api-asp

minFraud ASP API
ASP
3
star
50

webservice-paypal-paymentsadvanced

A simple wrapper around the PayPal Payments Advanced web service
Perl
3
star
51

dev-site

Static site generator for https://dev.maxmind.com.
MDX
3
star
52

xgb2code

A converter for xgboost model dumps to code.
Go
3
star
53

geoip-api-mscom

DEPRECATED GeoIP Legacy MS COM API
C
2
star
54

gatling-gen

C++
2
star
55

geolite2-ws-blogpost

Integrating MaxMind's Free and Paid IP Geolocation Web Services (in PHP)
PHP
2
star
56

App-CISetup

Command line tools to generate and update Travis and AppVeyor configs for Perl libraries
Perl
2
star
57

MaxMind-DB-Common-perl

Code shared by the MaxMind DB reader and writer modules
Perl
2
star
58

minfraud-api-perl

Perl API for minFraud Score, Insights, and Factors
Perl
2
star
59

WebService-PivotalTracker

Perl library for the Pivotal Tracker REST API
Perl
2
star
60

fuzzing-workshop

Code for Summit Fuzzing Workshop
Go
1
star
61

Dist-Zilla-PluginBundle-MAXMIND

Perl
1
star
62

TeamCity-Message

Generate TeamCity build messages
Perl
1
star
63

blog-site

Static site generator for https://blog.maxmind.com.
SCSS
1
star
64

api-specs

TypeScript
1
star
65

TAP-Formatter-TeamCity

Emit test results as TeamCity build messages
Perl
1
star