Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

mmdbctl is an MMDB file management CLI supporting various operations on MMDB database files.

License

NotificationsYou must be signed in to change notification settings

ipinfo/mmdbctl

Repository files navigation

IPinfo IPinfommdbctl

mmdbctl is an MMDB file management CLI byIPinfo.io that provides youthe following features:

  • Read data for IPs in an MMDB file.
  • Import data in non-MMDB format into MMDB.
  • Export data from MMDB format into non-MMDB format.
  • See the difference between two MMDB files.
  • Print the metadata of an MMDB file.
  • Check that an MMDB file is not corrupted or invalid.

Installation

Themmdbctl CLI is available for download via multiple mechanisms.

macOS

Install the latestamd64 version:

curl -Ls https://github.com/ipinfo/mmdbctl/releases/download/mmdbctl-1.4.8/macos.sh| sh

Debian / Ubuntu (amd64)

curl -Ls https://github.com/ipinfo/mmdbctl/releases/download/mmdbctl-1.4.8/deb.sh| sh

OR

curl -LO https://github.com/ipinfo/mmdbctl/releases/download/mmdbctl-1.4.8/mmdbctl_1.4.8.debsudo dpkg -i mmdbctl_1.4.8.deb

Windows Powershell

Note: run powershell as administrator before executing this command.

iwr -useb https://github.com/ipinfo/mmdbctl/releases/download/mmdbctl-1.4.8/windows.ps1| iex

Usinggo install

Make sure that$GOPATH/bin is in your$PATH, because that's where this getsinstalled:

go install github.com/ipinfo/mmdbctl@latest

Usingcurl/wget

The pre-built binaries for all platforms are available on GitHub via artifactsin releases. You need to simply download, unpack and move them to your shell'sbinary search path.

The following OS & arch combinations are supported (if you use one not listedon here, please open an issue):

darwin_amd64darwin_arm64dragonfly_amd64freebsd_386freebsd_amd64freebsd_armfreebsd_arm64linux_386linux_amd64linux_armlinux_arm64netbsd_386netbsd_amd64netbsd_armnetbsd_arm64openbsd_386openbsd_amd64openbsd_armopenbsd_arm64solaris_amd64windows_386windows_amd64windows_arm

After choosing a platformPLAT from above, run:

# for Windows, use ".zip" instead of ".tar.gz"curl -LO https://github.com/ipinfo/mmdbctl/releases/download/mmdbctl-1.4.8/mmdbctl_1.4.8_${PLAT}.tar.gz# ORwget https://github.com/ipinfo/mmdbctl/releases/download/mmdbctl-1.4.8/mmdbctl_1.4.8_${PLAT}.tar.gztar -xvf mmdbctl_1.4.8_${PLAT}.tar.gzmv mmdbctl_1.4.8_${PLAT} /usr/local/bin/mmdbctl

Usinggit

Installing from source requires at least the Golang version specified ingo.mod. You can install the Golang toolchain fromthe official site.

Once the correct Golang version is installed, simply clone the repository andinstall the binary:

git clone https://github.com/ipinfo/mmdbctlcd mmdbctlgo install.$GOPATH/bin/mmdbctl

You can add$GOPATH/bin to your$PATH to accessmmdbctl directly fromanywhere.

Alternatively, you can do the following to output the binary somewherespecific:

git clone https://github.com/ipinfo/mmdbctlcd mmdbctlgo build -o<path>.

Replace<path> with the required location.

Quick Start

This will help you quickly get started with themmdbctl CLI.

Default Help Message

By default, invoking the CLI shows a help message:

mmdbctl

Reading

You can read from MMDB files in various different ways - as individual IPs,CIDRs or IP ranges, coming from the command line as arguments, or from files,or from stdin.

Pretty JSON format:

$ mmdbctlread -f json-pretty 8.8.8.8 location.mmdb{"city":"Mountain View","country":"US","geoname_id":"5375480","latitude":"37.4056","longitude":"-122.0775","postalcode":"94043","region":"California","timezone":"America/Los_Angeles"}

CSV format:

$ mmdbctlread -f csv 8.8.8.8 location.mmdbip,city,country,geoname_id,latitude,longitude,postalcode,region,timezone8.8.8.8,Mountain View,US,5375480,37.4056,-122.0775,94043,California,America/Los_Angeles

TSV format:

$ mmdbctlread -f tsv 8.8.8.8 location.mmdbipcitycountrygeoname_idlatitudelongitudepostalcoderegiontimezone8.8.8.8Mountain ViewUS537548037.4056-122.077594043CaliforniaAmerica/Los_Angeles

Via a file:

$ cat ips.txt8.8.8.88.8.8.0/318.8.8.0-8.8.8.18.8.8.0,8.8.8.1$ mmdbctlread ips.txt location.mmdb| sort -u{"city":"Mountain View","country":"US","geoname_id":"5375480","latitude":"37.4056","longitude":"-122.0775","postalcode":"94043","region":"California","timezone":"America/Los_Angeles"}

Via stdin:

$echo 8.8.8.8| mmdbctlread location.mmdb{"city":"Mountain View","country":"US","geoname_id":"5375480","latitude":"37.4056","longitude":"-122.0775","postalcode":"94043","region":"California","timezone":"America/Los_Angeles"}

Multiple inputs are also possible - these all return the same thing:

$echo -e'8.8.8.8\n1.2.3.4'| mmdbctlread location.mmdb$ mmdbctlread 8.8.8.8 1.2.3.4 location.mmdb{"city":"Mountain View","country":"US","geoname_id":"5375480","latitude":"37.4056","longitude":"-122.0775","postalcode":"94043","region":"California","timezone":"America/Los_Angeles"}{"city":"Brisbane","country":"AU","geoname_id":"2174003","latitude":"-27.48203","longitude":"153.01358","postalcode":"4101","region":"Queensland","timezone":"Australia/Brisbane"}

Can check CIDRs and ranges - these will all return the same thing:

$ mmdbctlread 8.8.8.0/31 location.mmdb$ mmdbctlread 8.8.8.0-8.8.8.1 location.mmdb$ mmdbctlread 8.8.8.0,8.8.8.1 location.mmdb{"city":"Mountain View","country":"US","geoname_id":"5375480","latitude":"37.4056","longitude":"-122.0775","postalcode":"94043","region":"California","timezone":"America/Los_Angeles"}{"city":"Mountain View","country":"US","geoname_id":"5375480","latitude":"37.4056","longitude":"-122.0775","postalcode":"94043","region":"California","timezone":"America/Los_Angeles"}{"city":"Mountain View","country":"US","geoname_id":"5375480","latitude":"37.4056","longitude":"-122.0775","postalcode":"94043","region":"California","timezone":"America/Los_Angeles"}

Importing

Importing allows taking in files as CSV/TSV/JSON, and outputting an MMDB file.

Importing is one of the most powerful/flexible features inmmdbctl. However,we only allow strings throughout the data at the current time.

Seemmdbctl import --help for full details on usage.

Here are some basic examples:

# basic CSV importing into MMDB.$ mmdbctl import --in data.csv --out data.mmdb# generate MMDB from a TSV file containing IPv4 data.$ cat data.tsv| mmdbctl import --ip 4 --tsv --out data.mmdb# don't include the implicit `network` field in the output MMDB:$ mmdbctl import --no-network --in data.csv --out data.mmdb# generate an MMDB without any fields, just IP ranges that meet a criteria.$ mmdbctl import                                                              \    --size 24 --no-fields --ip 4                                              \    --in anycast.csv --out anycast.mmdb

Exporting

Exporting allows taking in an MMDB file and outputting CSV/TSV/JSON.

Seemmdbctl export --help for full details on usage.

# basic export.$ mmdbctlexport data.mmdb data.csv# basic export without a header.$ mmdbctlexport --no-header data.mmdb data.csv# just see the number of entries it'd output.$ mmdbctlexport --no-header --format csv data.mmdb| wc -l

Metadata

You can retrieve data in themetadata section of the MMDB file using themetadata subcommand.

Pretty format:

$ mmdbctl metadata location.mmdb- Binary Format 2.0- Database Type ipinfo location.mmdb- IP Version    4- Record Size   32- Node Count    123456789- Description    en ipinfo location.mmdb- Languages     en- Build Epoch   123456789

JSON format:

$ mmdbctl metadata -f json location.mmdb{"binary_format":"2.0","db_type":"ipinfo location.mmdb","ip": 4,"record_size": 32,"node_count": 123456789,"description": {"en":"ipinfo location.mmdb"    },"languages": ["en"    ],"build_epoch": 123456789}

Verification

You can verify if a MMDB file is correctly structured with theverifysubcommand:

$ mmdbctl verify location.mmdbvalid

Let's force it to be invalid and check again:

$ cp location.mmdb location-tmp.mmdb$ cat location.mmdb>> location-tmp.mmdb$ mmdbctl verify location-tmp.mmdbinvalid: received decoding error (the MaxMind DB file's data section contains bad data (uint16 size of 11)) at offset of 13825601

Auto-Completion

Auto-completion is supported for at least the following shells:

bashzshfish

NOTE: it may work for other shells as well because the implementation is inGolang and is not necessarily shell-specific.

Installation

Installing auto-completions is as simple as running one command (works forbash,zsh andfish shells):

mmdbctl completion install

If you want to customize the installation process (e.g. in case theauto-installation doesn't work as expected), you can request the actualcompletion script for each shell:

# get bash completion scriptmmdbctl completion bash# get zsh completion scriptmmdbctl completion zsh# get fish completion scriptmmdbctl completion fish

Shell not listed?

If your shell is not listed here, you can open an issue.

Note that as long as theCOMP_LINE environment variable is provided to thebinary itself, it will output completion results. So if your shell provides away to passCOMP_LINE on auto-completion attempts to a binary, then have yourshell do that with themmdbctl binary itself (or any of our binaries).

Color Output

Disabling Color Output

All our CLIs respect either the--nocolor flag or theNO_COLOR environment variable to disable coloroutput.

Color on Windows

To enable color support for the Windows command prompt, run the following toenableConsole Virtual Terminal Sequences.

REG ADD HKCU\CONSOLE /f /v VirtualTerminalLevel /t REG_DWORD /d1

You can disable this by running the following:

REG DELETE HKCU\CONSOLE /f /v VirtualTerminalLevel

Other IPinfo Tools

There are official IPinfo client libraries available for many languages including PHP, Python, Go, Java, Ruby, and many popular frameworks such as Django, Rails and Laravel. There are also many third party libraries and integrations available for our API.

Seehttps://ipinfo.io/developers/libraries for more details.

About IPinfo

Founded in 2013, IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier, VPN detection, hosted domains, and IP type data sets. Our API handles over 40 billion requests a month for businesses and developers.

image

About

mmdbctl is an MMDB file management CLI supporting various operations on MMDB database files.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors10


[8]ページ先頭

©2009-2025 Movatter.jp