Open pbiering opened 4 years ago
+1 I was about to open the same issue. For people just trying to use this as a one-liner (which is probably >90% of people arriving here), forcing them to dive into the JSON tree with jq
or other commands is somewhat cumbersome.
It would be great if the use case of "just get me the raw city, country for this IP" is covered without needing external commands.
$ mmdbinspect -db somedb.mmdb -format '{.city.names.en}, {.country.names.en}' 123.123.123.123
Transylvania, Romania
Thanks for the feedback! Something like you describe sounds useful, although having something flexible enough for all use cases might be a challenge. We could probably expand the examples to cover some more cases as a step in this direction.
In the mindset of "Do One Thing And Do It Well", I think it would suffice to show some examples in the examples section of the README.md on how to extract some common queries using jq and link to the jq tutorials for advanced use cases.
In the mindset of "Do One Thing And Do It Well", I think it would suffice to show some examples in the examples section of the README.md on how to extract some common queries using jq and link to the jq tutorials for advanced use cases.
somehow convinced if I compare sniplets extracting the country code from the past (GeoIP v1):
$ geoiplookup -i 1.1.1.1 | awk 'match($0, /GeoIP.*: ([A-Z0-9]+),.*/, a) { print a[1]; exit; }'
AU
with present (GeoIP v2 / MMDB)
$ mmdbinspect --db /var/local/share/GeoIP/GeoLite2-City.mmdb 1.1.1.1 | jq -r '.[].Records[].Record.country.iso_code'
AU
or
$ mmdblookup -f /var/local/share/GeoIP/GeoLite2-City.mmdb --ip 1.1.1.1 country iso_code | awk 'match($0, /.*"([A-Z0-9]+)".*/, a ) { print a[1]; exit; }'
AU
Advertisment: ipv6vcalc
can do this in one-shot
$ ipv6calc -q --addr2cc 1.1.1.1
AU
BTW:
mmdblookup
is packaged in EL versions in libmaxminddb
RPMmmdbinspect
isn't so far available in any repository: https://pkgs.org/search/?q=mmdbinspect (empty result) but only available from Github: https://github.com/maxmind/mmdbinspect/releases
I don't know how others are thinking about, but having the option to lookup a dedicated element of the JSON treen and return this in a simple output line (optionally with element=value to be used in "eval") would be a great advantage for any script related action to avoid using any sophisticated pipe methods e.g. in Bash to get the value of one element...