- Notifications
You must be signed in to change notification settings - Fork20
mmdbctl is an MMDB file management CLI supporting various operations on MMDB database files.
License
ipinfo/mmdbctl
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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.
Themmdbctl CLI is available for download via multiple mechanisms.
Install the latestamd64 version:
curl -Ls https://github.com/ipinfo/mmdbctl/releases/download/mmdbctl-1.4.8/macos.sh| shcurl -Ls https://github.com/ipinfo/mmdbctl/releases/download/mmdbctl-1.4.8/deb.sh| shOR
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
Note: run powershell as administrator before executing this command.
iwr -useb https://github.com/ipinfo/mmdbctl/releases/download/mmdbctl-1.4.8/windows.ps1| iexMake sure that$GOPATH/bin is in your$PATH, because that's where this getsinstalled:
go install github.com/ipinfo/mmdbctl@latest
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_armAfter 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
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.
This will help you quickly get started with themmdbctl CLI.
By default, invoking the CLI shows a help message:
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_AngelesTSV format:
$ mmdbctlread -f tsv 8.8.8.8 location.mmdbipcitycountrygeoname_idlatitudelongitudepostalcoderegiontimezone8.8.8.8Mountain ViewUS537548037.4056-122.077594043CaliforniaAmerica/Los_AngelesVia 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 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 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
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}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 is supported for at least the following shells:
bashzshfishNOTE: it may work for other shells as well because the implementation is inGolang and is not necessarily shell-specific.
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
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).
All our CLIs respect either the--nocolor flag or theNO_COLOR environment variable to disable coloroutput.
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 VirtualTerminalLevelThere 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.
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.
About
mmdbctl is an MMDB file management CLI supporting various operations on MMDB database files.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors10
Uh oh!
There was an error while loading.Please reload this page.
