|
| 1 | +# MaxMind DB Reader # |
| 2 | + |
| 3 | +**NOTE**: This is an alpha release, and the API may change before the final |
| 4 | +production release. |
| 5 | + |
| 6 | +## Description ## |
| 7 | + |
| 8 | +MaxMind DB is a binary file format that stores data indexed by IP address |
| 9 | +subnets (IPv4 or IPv6). |
| 10 | + |
| 11 | +This repository contains the spec for the format, tools for creating MaxMind |
| 12 | +DB files, and the Perl API for reading such files. |
| 13 | + |
| 14 | + |
| 15 | +## Installation ## |
| 16 | + |
| 17 | +### Define Your Dependencies ### |
| 18 | + |
| 19 | +We recommend installing this package with [Maven](http://maven.apache.org/). |
| 20 | +To do this, add the dependency to your pom.xml: |
| 21 | + |
| 22 | +```xml |
| 23 | + <dependency> |
| 24 | + <groupId>com.maxmind.maxminddb</groupId> |
| 25 | + <artifactId>maxminddb</artifactId> |
| 26 | + <version>0.1.0</version> |
| 27 | + </dependency> |
| 28 | +``` |
| 29 | + |
| 30 | +## Usage ## |
| 31 | + |
| 32 | +*Note:* For accessing MaxMind GeoIP2 databases, we generally recommend |
| 33 | +using the GeoIP2 Java API rather than using this package directly. |
| 34 | + |
| 35 | +To use the API, you must first create a `Reader` object. The constructor |
| 36 | +for the reader object takes a `File` representing your MaxMind DB. Optionally |
| 37 | +you may pass a second parameter with a `FileMode` of `MEMORY_MAP` or |
| 38 | +`IN_MEMORY`. The default mode is `MEMORY_MAP`, which maps the file to virtual |
| 39 | +memory. This often provides performance comparable to loading the file into |
| 40 | +real memory with `IN_MEMORY` while using significantly less memory. |
| 41 | + |
| 42 | +To look up an IP address, pass the address as an `InetAddress` to the `get` |
| 43 | +method on `Reader`. This method will return the result as a |
| 44 | +`com.fasterxml.jackson.databind.JsonNode` object. `JsonNode` objects are |
| 45 | +used as they provide a convenient representation of multi-type data |
| 46 | +structures and the databind package of Jackson 2 supplies many tools for |
| 47 | +interacting with the data in this format. |
| 48 | + |
| 49 | +## Example ## |
| 50 | + |
| 51 | +```java |
| 52 | + |
| 53 | +File database = new File("/path/to/database/GeoIP2-City.mmdb"); |
| 54 | +Reader reader = new Reader(database); |
| 55 | + |
| 56 | +InetAddress address = InetAddress.getByName("24.24.24.24"); |
| 57 | + |
| 58 | +JsonNode result = reader.get(address); |
| 59 | + |
| 60 | +System.out.println(result); |
| 61 | + |
| 62 | +``` |
| 63 | +## Format ## |
| 64 | + |
| 65 | +The MaxMind DB format is an open format for quickly mapping IP addresses |
| 66 | +to records. The [specification](https://github.com/maxmind/MaxMind-DB-perl/blob/master/docs/MaxMind-IPDB-spec.md) is available as part of our |
| 67 | +[Perl writer](https://github.com/maxmind/MaxMind-DB-perl) for the format. |
| 68 | + |
| 69 | +## Bug Tracker ## |
| 70 | + |
| 71 | +Please report all issues with this code using the [GitHub issue tracker] |
| 72 | +(https://github.com/maxmind/MaxMind-DB-java/issues). |
| 73 | + |
| 74 | +If you are having an issue with a MaxMind database or service that is not |
| 75 | +specific to this reader, please [contact MaxMind support] |
| 76 | +(http://www.maxmind.com/en/support). |
| 77 | + |
| 78 | +## Requirements ## |
| 79 | + |
| 80 | +Maxmind has tested this API with Java 6 and above. Reasonable patches |
| 81 | +for Java 5 will be accepted. Patches for 1.4 or earlier will not be |
| 82 | +accepted. |
| 83 | + |
| 84 | +## Contributing ## |
| 85 | + |
| 86 | +Patches and pull requests are encouraged. Please include unit tests whenever |
| 87 | +possible. |
| 88 | + |
| 89 | +## Versioning ## |
| 90 | + |
| 91 | +The MaxMind DB Reader API uses [Semantic Versioning](http://semver.org/). |
| 92 | + |
| 93 | +## Copyright and License ## |
| 94 | + |
| 95 | +This software is Copyright (c) 2013 by MaxMind, Inc. |
| 96 | + |
| 97 | +This is free software, licensed under the Apache License, Version 2.0. |
0 commit comments