mteodoro / mmutils

Tools for working with MaxMind GeoIP csv and dat files
MIT License
95 stars 47 forks source link

any chance of your script supporting the new MMDB format? #10

Open jhaar opened 8 years ago

jhaar commented 8 years ago

Hi there

I'd first like to thank you for your csv2dat.py script. I have used it to merge the lat/long positions of our internal 10/8 network subnets into the maxmind CSV files and now we can do things like have maps showing our internal devices using websites/etc as well as Internet :-)

However, now we're seeing applications that only support the newer MMDB format. Have you thought about adding support for that as an option? So far there only seems to be a perl "writer" from Maxmind - but nothing for python :-(

In any case, thanks for your work!

Jason

mnicky commented 6 years ago

Hi Jason, I was successful using pyperler to call Maxmind's writer perl library from python. Example code:

#!/usr/bin/env python3

import pyperler

i = pyperler.Interpreter()
tree = i.use("MaxMind::DB::Writer::Tree")
types_t = i("my %types = (city => 'map', \
                          traits => 'map', \
                          country => 'map', \
                          ); sub { $types{ $_[0] } }")

treeInst = tree.new(ip_version=6,
                    record_size=28,
                    database_type='GeoIP2-City',
                    languages=['en'],
                    description = {'en': 'test-db'},
                    map_key_type_callback=types_t,
                    alias_ipv6_to_ipv4=True
                    # merge_record_collisions = True
                    )

treeInst.insert_network(ip, record)
# ...

fh = i.use("FileHandle")
fh = fh.new()
fh.open('>' + 'geocity.mmdb')
treeInst.write_tree(fh)