diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..1861f46 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,55 @@ +--- +name: Build +on: [push] + +jobs: + build: + name: build + runs-on: ubuntu-latest + strategy: + matrix: + go-version: ['1.12.x', '1.13.x'] + include: + - go-version: '1.13.x' + build-coverage: true + steps: + - name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go-version }} + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + + - name: Fetch submodules + run: git submodule init && git submodule update + + - name: Get dependencies + run: | + go get -v -t -d ./... + if [ -f Gopkg.toml ]; then + curl + https://raw.githubusercontent.com/golang/dep/master/install.sh | sh + dep ensure + fi + + - name: Build + run: go build -v ./... + + - name: Test with coverage + run: ${{ format('go test -race -coverprofile=cover.{0}.gcov -covermode=atomic ./...', matrix.go-version) }} + + - name: Convert coverage output to lcov + uses: jandelgado/gcov2lcov-action@v1.0.0 + with: + infile: ${{ format('cover.{0}.gcov', matrix.go-version) }} + outfile: ${{ format('cover.{0}.lcov', matrix.go-version) }} + if: matrix.build-coverage && success() + + - name: Upload coverage + uses: coverallsapp/github-action@v1.0.1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ${{ format('cover.{0}.lcov', matrix.go-version) }} + if: matrix.build-coverage && success() diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index 900aec5..0000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,40 +0,0 @@ ---- -name: Go -on: [push] -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - name: Set up Go 1.13 - uses: actions/setup-go@v1 - with: - go-version: 1.13 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v1 - - - name: Fetch submodules - run: git submodule init && git submodule update - - - name: Get dependencies - run: | - go get -v -t -d ./... - if [ -f Gopkg.toml ]; then - curl - https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - dep ensure - fi - - - name: Build - run: go build -v ./... - - - name: Test - run: go test -race -coverprofile=coverage.txt -covermode=atomic ./... - - - name: Upload coverage - run: bash <(curl -s https://codecov.io/bash) - env: - CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} - if: success() diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..822e58b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/cover.*.gcov +/cover.*.lcov +/dist/** \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..0c0d8e5 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,63 @@ +project_name: 'mmdbinspect' + +env: + - 'GO111MODULE=on' + +before: + hooks: + - 'go mod tidy' + +builds: + - id: 'mmdbinspect' + main: './cmd/mmdbinspect/main.go' + binary: 'mmdbinspect' + goos: + - 'darwin' + - 'linux' + - 'windows' + ignore: + - goos: 'darwin' + goarch: '386' + +archives: + - id: 'mmdbinspect' + builds: + - 'mmdbinspect' + replacements: + darwin: 'Darwin' + linux: 'Linux' + windows: 'Windows' + 386: 'i386' + amd64: 'x86_64' + wrap_in_directory: true + format_overrides: + - goos: windows + format: zip + +checksum: + name_template: 'checksums.txt' + +snapshot: + name_template: "{{ .Tag }}-next" + +changelog: + skip: true + +nfpms: + - id: 'mmdbinspect' + builds: + - 'mmdbinspect' + vendor: 'MaxMind, Inc.' + homepage: 'https://www.maxmind.com/' + maintainer: 'MaxMind, Inc. ' + description: 'Program to look up records for one or more IPs/networks in one or more .mmdb databases.' + license: 'Apache 2.0 or MIT' + formats: + - 'deb' + - 'rpm' + bindir: '/usr/bin' + files: + 'CHANGELOG.md': '/usr/share/doc/mmdbinspect/CHANGELOG.md' + 'LICENSE-APACHE': '/usr/share/doc/mmdbinspect/LICENSE-APACHE' + 'LICENSE-MIT': '/usr/share/doc/mmdbinspect/LICENSE-MIT' + 'README.md': '/usr/share/doc/mmdbinspect/README.md' diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f2c27d7 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# CHANGELOG + +## 0.0.0 (2020-02-10) + +* Initial beta release diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index 55bab4b..deffa7c 100644 --- a/README.md +++ b/README.md @@ -1,337 +1,409 @@ -Inspect `.mmdb` databases +## mmdbinspect + +`mmdbinspect` - look up records for one or more IPs/networks in one or more .mmdb databases + +[![Build Status](https://github.com/maxmind/mmdbinspect/workflows/Build/badge.svg)](https://github.com/maxmind/mmdbinspect/actions?query=workflow%3A%22Build%22) +[![Coverage Status](https://coveralls.io/repos/github/maxmind/mmdbinspect/badge.svg)](https://coveralls.io/github/maxmind/mmdbinspect) + +## Usage + +```bash +mmdbinspect -db + db Path to a MMDB file. Can be specified multiple times. + 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](https://github.com/maxmind/mmdbinspect/issues). + +## Installation + +### Installing via binary release + +[Release binaries](https://github.com/maxmind/mmdbinspect/releases) have been made available for several popular platorms. 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](https://golang.org)._ + +The easiest way is via `go get`: ```bash -cd cmd/mmdbinspect -go build -./mmdbinspect --db ../../GeoLite2-Country.mmdb --db ../../dbs/GeoLite2-City.mmdb 130.113.64.30/24 0:0:0:0:0:ffff:8064:a678 +$ go get -u github.com/maxmind/mmdbinspect ``` -Yields: +This installs `mmdbinspect` to `$GOPATH/bin/mmdbinspect`. + +## Examples + +The following examples were created using our test databases which can be found in `test/data` in this repository. + +
+ A simple lookup (one IP/network, one DB) ```bash +$ mmdbinspect -db GeoIP2-Anonymous-IP-Test.mmdb 71.160.223.3 [ { - "Database": "../../GeoLite2-Country.mmdb", + "Database": "GeoIP2-Anonymous-IP-Test.mmdb", "Records": [ { - "Network": "130.113.64.0/16", + "Network": "71.160.223.3/24", "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": 6251999, - "iso_code": "CA", - "names": { - "de": "Kanada", - "en": "Canada", - "es": "Canadá", - "fr": "Canada", - "ja": "カナダ", - "pt-BR": "Canadá", - "ru": "Канада", - "zh-CN": "加拿大" - } - }, - "registered_country": { - "geoname_id": 6251999, - "iso_code": "CA", - "names": { - "de": "Kanada", - "en": "Canada", - "es": "Canadá", - "fr": "Canada", - "ja": "カナダ", - "pt-BR": "Canadá", - "ru": "Канада", - "zh-CN": "加拿大" - } - } + "is_anonymous": true, + "is_hosting_provider": true } } ], - "Lookup": "130.113.64.30/24" - }, + "Lookup": "71.160.223.3" + } +] +``` +
+ +
+ Look up one IP/network in multiple databases + +```bash +$ mmdbinspect -db GeoIP2-Country-Test.mmdb -db GeoIP2-City-Test.mmdb 202.196.224.4 +[ { - "Database": "../../GeoLite2-Country.mmdb", + "Database": "GeoIP2-Country-Test.mmdb", "Records": [ { - "Network": "128.100.166.120/16", + "Network": "202.196.224.4/20", "Record": { "continent": { - "code": "NA", - "geoname_id": 6255149, + "code": "AS", + "geoname_id": 6255147, "names": { - "de": "Nordamerika", - "en": "North America", - "es": "Norteamérica", - "fr": "Amérique du Nord", - "ja": "北アメリカ", - "pt-BR": "América do Norte", - "ru": "Северная Америка", - "zh-CN": "北美洲" + "de": "Asien", + "en": "Asia", + "es": "Asia", + "fr": "Asie", + "ja": "アジア", + "pt-BR": "Ásia", + "ru": "Азия", + "zh-CN": "亚洲" } }, "country": { - "geoname_id": 6251999, - "iso_code": "CA", + "geoname_id": 1694008, + "iso_code": "PH", "names": { - "de": "Kanada", - "en": "Canada", - "es": "Canadá", - "fr": "Canada", - "ja": "カナダ", - "pt-BR": "Canadá", - "ru": "Канада", - "zh-CN": "加拿大" + "de": "Philippinen", + "en": "Philippines", + "es": "Filipinas", + "fr": "Philippines", + "ja": "フィリピン共和国", + "pt-BR": "Filipinas", + "ru": "Филиппины", + "zh-CN": "菲律宾" } }, "registered_country": { - "geoname_id": 6251999, - "iso_code": "CA", + "geoname_id": 1694008, + "iso_code": "PH", "names": { - "de": "Kanada", - "en": "Canada", - "es": "Canadá", - "fr": "Canada", - "ja": "カナダ", - "pt-BR": "Canadá", - "ru": "Канада", - "zh-CN": "加拿大" + "de": "Philippinen", + "en": "Philippines", + "es": "Filipinas", + "fr": "Philippines", + "ja": "フィリピン共和国", + "pt-BR": "Filipinas", + "ru": "Филиппины", + "zh-CN": "菲律宾" } + }, + "represented_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": "美国" + }, + "type": "military" } } } ], - "Lookup": "0:0:0:0:0:ffff:8064:a678" + "Lookup": "202.196.224.4" }, { - "Database": "../../dbs/GeoLite2-City.mmdb", + "Database": "GeoIP2-City-Test.mmdb", "Records": [ { - "Network": "130.113.64.0/16", + "Network": "202.196.224.4/20", "Record": { - "city": { - "geoname_id": 5969782, - "names": { - "en": "Hamilton", - "ja": "ハミルトン", - "ru": "Гамильтон", - "zh-CN": "哈密尔顿" - } - }, "continent": { - "code": "NA", - "geoname_id": 6255149, + "code": "AS", + "geoname_id": 6255147, "names": { - "de": "Nordamerika", - "en": "North America", - "es": "Norteamérica", - "fr": "Amérique du Nord", - "ja": "北アメリカ", - "pt-BR": "América do Norte", - "ru": "Северная Америка", - "zh-CN": "北美洲" + "de": "Asien", + "en": "Asia", + "es": "Asia", + "fr": "Asie", + "ja": "アジア", + "pt-BR": "Ásia", + "ru": "Азия", + "zh-CN": "亚洲" } }, "country": { - "geoname_id": 6251999, - "iso_code": "CA", + "geoname_id": 1694008, + "iso_code": "PH", "names": { - "de": "Kanada", - "en": "Canada", - "es": "Canadá", - "fr": "Canada", - "ja": "カナダ", - "pt-BR": "Canadá", - "ru": "Канада", - "zh-CN": "加拿大" + "de": "Philippinen", + "en": "Philippines", + "es": "Filipinas", + "fr": "Philippines", + "ja": "フィリピン共和国", + "pt-BR": "Filipinas", + "ru": "Филиппины", + "zh-CN": "菲律宾" } }, "location": { - "accuracy_radius": 5, - "latitude": 43.2642, - "longitude": -79.9143, - "time_zone": "America/Toronto" + "accuracy_radius": 121, + "latitude": 13, + "longitude": 122, + "time_zone": "Asia/Manila" }, "postal": { - "code": "L8S" + "code": "34021" }, "registered_country": { - "geoname_id": 6251999, - "iso_code": "CA", + "geoname_id": 1694008, + "iso_code": "PH", "names": { - "de": "Kanada", - "en": "Canada", - "es": "Canadá", - "fr": "Canada", - "ja": "カナダ", - "pt-BR": "Canadá", - "ru": "Канада", - "zh-CN": "加拿大" + "de": "Philippinen", + "en": "Philippines", + "es": "Filipinas", + "fr": "Philippines", + "ja": "フィリピン共和国", + "pt-BR": "Filipinas", + "ru": "Филиппины", + "zh-CN": "菲律宾" } }, - "subdivisions": [ - { - "geoname_id": 6093943, - "iso_code": "ON", - "names": { - "en": "Ontario", - "fr": "Ontario", - "ja": "オンタリオ州", - "pt-BR": "Ontário", - "ru": "Онтарио", - "zh-CN": "安大略" - } - } - ] + "represented_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": "美国" + }, + "type": "military" + } + } + } + ], + "Lookup": "202.196.224.4" + } +] +``` +
+ +
+ Look up multiple IPs/networks in a single database + +```bash +$ mmdbinspect -db GeoIP2-Connection-Type-Test.mmdb 1.0.9.16/28 2003::ff00:3a4c/128 +[ + { + "Database": "GeoIP2-Connection-Type-Test.mmdb", + "Records": [ + { + "Network": "1.0.9.16/21", + "Record": { + "connection_type": "Dialup" } } ], - "Lookup": "130.113.64.30/24" + "Lookup": "1.0.9.16/28" }, { - "Database": "../../dbs/GeoLite2-City.mmdb", + "Database": "GeoIP2-Connection-Type-Test.mmdb", "Records": [ { - "Network": "128.100.166.120/16", + "Network": "2003::ff00:3a4c/24", "Record": { - "city": { - "geoname_id": 6167865, - "names": { - "de": "Toronto", - "en": "Toronto", - "es": "Toronto", - "fr": "Toronto", - "ja": "トロント", - "pt-BR": "Toronto", - "ru": "Торонто", - "zh-CN": "多伦多" - } - }, - "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": 6251999, - "iso_code": "CA", - "names": { - "de": "Kanada", - "en": "Canada", - "es": "Canadá", - "fr": "Canada", - "ja": "カナダ", - "pt-BR": "Canadá", - "ru": "Канада", - "zh-CN": "加拿大" - } - }, - "location": { - "accuracy_radius": 5, - "latitude": 43.6638, - "longitude": -79.3999, - "time_zone": "America/Toronto" - }, - "postal": { - "code": "M5S" - }, - "registered_country": { - "geoname_id": 6251999, - "iso_code": "CA", - "names": { - "de": "Kanada", - "en": "Canada", - "es": "Canadá", - "fr": "Canada", - "ja": "カナダ", - "pt-BR": "Canadá", - "ru": "Канада", - "zh-CN": "加拿大" - } - }, - "subdivisions": [ - { - "geoname_id": 6093943, - "iso_code": "ON", - "names": { - "en": "Ontario", - "fr": "Ontario", - "ja": "オンタリオ州", - "pt-BR": "Ontário", - "ru": "Онтарио", - "zh-CN": "安大略" - } - } - ] + "connection_type": "Cable/DSL" + } + } + ], + "Lookup": "2003::ff00:3a4c/128" + } +] +``` +
+ +
+ Look up multiple IPs/networks in multiple databases + +```bash +$ mmdbinspect -db GeoIP2-Static-IP-Score-Test.mmdb -db GeoIP2-User-Count-Test.mmdb 1.2.3.5 1.2.3.66 +[ + { + "Database": "GeoIP2-Static-IP-Score-Test.mmdb", + "Records": [ + { + "Network": "1.2.3.5/32", + "Record": { + "score": 0.06 + } + } + ], + "Lookup": "1.2.3.5" + }, + { + "Database": "GeoIP2-Static-IP-Score-Test.mmdb", + "Records": [ + { + "Network": "1.2.3.66/26", + "Record": { + "score": 0.12 } } ], - "Lookup": "0:0:0:0:0:ffff:8064:a678" + "Lookup": "1.2.3.66" + }, + { + "Database": "GeoIP2-User-Count-Test.mmdb", + "Records": [ + { + "Network": "1.2.3.5/32", + "Record": { + "ipv4_24": 4, + "ipv4_32": 1 + } + } + ], + "Lookup": "1.2.3.5" + }, + { + "Database": "GeoIP2-User-Count-Test.mmdb", + "Records": [ + { + "Network": "1.2.3.66/26", + "Record": { + "ipv4_24": 4, + "ipv4_32": 0 + } + } + ], + "Lookup": "1.2.3.66" } ] ``` +
-Or, pipe it to `jq`: +
+ Look up a file of IPs/networks using the `xargs` utility ```bash -./mmdbinspect \ ---db ../../GeoLite2-Country.mmdb \ ---db ../../dbs/GeoLite2-City.mmdb \ -130.113.64.30/24 0:0:0:0:0:ffff:8064:a678 \ -| jq '.[] | {database: .Database, Lookup: .Lookup, Network: .Records[].Network, Country: .Records[].Record.country.names.en, City: .Records[].Record.city.names.en,}' +$ cat list.txt +5.83.124.0/20 +216.160.83.0/27 +$ cat list.txt | xargs mmdbinspect -db GeoIP2-DensityIncome-Test.mmdb +[ + { + "Database": "GeoIP2-DensityIncome-Test.mmdb", + "Records": [ + { + "Network": "5.83.124.0/22", + "Record": { + "average_income": 32323, + "population_density": 1232 + } + } + ], + "Lookup": "5.83.124.0/20" + }, + { + "Database": "GeoIP2-DensityIncome-Test.mmdb", + "Records": [ + { + "Network": "216.160.83.0/24", + "Record": { + "average_income": 24626, + "population_density": 1341 + } + } + ], + "Lookup": "216.160.83.0/27" + } +] ``` +
+ +
+Tame the output with the `jq` utility -Yields: ```bash -Country: .Records[].Record.country.names.en, City: .Records[].Record.city.names.en,}' -{ - "database": "../../GeoLite2-Country.mmdb", - "Lookup": "130.113.64.30/24", - "Network": "130.113.64.0/16", - "Country": "Canada", - "City": null -} -{ - "database": "../../GeoLite2-Country.mmdb", - "Lookup": "0:0:0:0:0:ffff:8064:a678", - "Network": "128.100.166.120/16", - "Country": "Canada", - "City": null -} -{ - "database": "../../dbs/GeoLite2-City.mmdb", - "Lookup": "130.113.64.30/24", - "Network": "130.113.64.0/16", - "Country": "Canada", - "City": "Hamilton" -} -{ - "database": "../../dbs/GeoLite2-City.mmdb", - "Lookup": "0:0:0:0:0:ffff:8064:a678", - "Network": "128.100.166.120/16", - "Country": "Canada", - "City": "Toronto" -} +$ mmdbinspect -db GeoIP2-ISP-Test.mmdb 5.145.96.0 | jq '.[] | .Records[].Record.isp' +"Finecom" ``` +
+ +## Bug Reports + +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). + +## Copyright and License + +This software is Copyright (c) 2019 - 2020 by MaxMind, Inc. + +This is free software, licensed under the [Apache License, Version 2.0](LICENSE-APACHE) or the [MIT License](LICENSE-MIT), at your option. \ No newline at end of file diff --git a/cmd/mmdbinspect/main.go b/cmd/mmdbinspect/main.go index 972f59c..3dcaa6f 100644 --- a/cmd/mmdbinspect/main.go +++ b/cmd/mmdbinspect/main.go @@ -7,7 +7,7 @@ import ( "os" "strings" - "github.com/oalders/mmdbinspect/pkg/mmdbinspect" + "github.com/maxmind/mmdbinspect/pkg/mmdbinspect" ) type arrayFlags []string diff --git a/go.mod b/go.mod index 651deaa..dbb2786 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/oalders/mmdbinspect +module github.com/maxmind/mmdbinspect go 1.13