Skip to content

Adding ipv4 and ipv6 breaks lookup ability with maxmind reader #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
aaronpeterson opened this issue May 22, 2019 · 0 comments
Open

Comments

@aaronpeterson
Copy link

aaronpeterson commented May 22, 2019

I can only seem to insert ipv4 into my files otherwise they become unreadable. If I write all ipv4 and even a single ipv6 the lookup using a maxmind reader fails (no errors, just empty results).

I believe the issue I am having is in how I am adding the ipv4 addresses.

import os
import mmdbencoder

OUTPUT_MMDB_FILENAME = 'output.mmdb'

if os.path.isfile(OUTPUT_MMDB_FILENAME):
    print("WARNING: Deleting Old MMDB File")
    os.remove(OUTPUT_MMDB_FILENAME)

mmdb_file = open(OUTPUT_MMDB_FILENAME, 'wb');

enc = mmdbencoder.Encoder(
    # Using 0th index
    6,
    32,
    'suspect',
    ['en'],  # Languages
    {'en': 'Description...'},  # Description
    compat=True)

# Remove the ipv6 and the ipv4 are readable, add them and only ipv6 are readable
ips = [
    '216.244.66.248',
    '3.15.9.167',
    '2a02:587:a12:f000:e9bf:9b70:4fd:c66',
    '2002:b9ea:da6b:0:0:0:b9ea:da6b',
    '192.0.91.147'
]

# just the same for all of these...
data = enc.insert_data({'region': 'United States', 'type': 'attack_source'})

for ip in ips:
    try:
        enc.insert_network(ip, data)
    except Exception as e:
        print("ERROR: Got error while adding row to the mmdb file. Details are below")
        print("-----: Error: {}".format(str(e)))

enc.write(mmdb_file)

print("Done")

There was some confusion in the Official Perl writer as well but I can't seem to figure out any ipv6 representation of an ipv4 that works such as:

maxmind/MaxMind-DB-Writer-perl#44 (comment)

@aaronpeterson aaronpeterson changed the title How to add multiple lines from a csv Adding ipv4 and ipv6 breaks lookup ability with maxmind reader May 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant