Ip to location database


Keywords
ip, ip-location, ip-location-db, ipv4, ipv6, location, asn, autonomous, mmdb, autonomous-system, geoip, ip-country, ip-geolocation, ip2country, ip2location
Licenses
NLPL/MulanPSL-2.0
Install
npm install @ip-location-db/geolite2-asn-mmdb@2.3.2024081718

Documentation

ip-location-db

This project provides IP to location databases in CSV and MMDB formats.

There are 3 types of IP database in this repository: country, city and asn files. All have their own standard format.

Country

ip_range_start, ip_range_end, country_code
Database Type License Updated IPv4 IPv6 IPv4-num IPv6-num
ASN

npm version
npm version
Country CC0 Daily CSV
MMDB
CSV
MMDB
CSV CSV
GeoFeed + ASN

npm version
npm version
Country CC0 Daily CSV
MMDB
CSV
MMDB
CSV CSV
GeoFeed + Whois + ASN

npm version
npm version
Country CC0 Daily CSV
MMDB
CSV
MMDB
CSV CSV
IPtoASN

npm version
npm version
Country PDDL by IPtoASN Daily CSV
MMDB
CSV
MMDB
CSV CSV
DB-IP Lite

npm version
Country CC BY 4.0
by DB-IP
Monthly CSV
MMDB
CSV
MMDB
CSV CSV
DB-IP Lite + GeoFeed + Whois + ASN

npm version
Country CC BY 4.0
by DB-IP
Monthly CSV
MMDB
CSV
MMDB
CSV CSV
GeoLite2

npm version
npm version
Country GeoLite2 License by MaxMind Twice weekly CSV
MMDB
CSV
MMDB
CSV CSV
GeoLite2 + GeoFeed + Whois + ASN

npm version
npm version
Country GeoLite2 License by MaxMind Daily CSV
MMDB
CSV
MMDB
CSV CSV

City

ip_range_start, ip_range_end, country_code, city, state1, state2, latitude, longitude, postcode, timezone
Database Type License Updated IPv4 IPv6 IPv4-num IPv6-num
DB-IP Lite

npm version
npm version
npm version
City CC BY 4.0
by DB-IP
Monthly CSV.gz
CSV.7z
MMDB
CSV.gz
CSV.7z
MMDB
CSV.gz
CSV.7z
CSV.gz
CSV.7z
GeoLite2

npm version
npm version
npm version
City GeoLite2 License by MaxMind Twice weekly CSV.gz
CSV.7z
MMDB
CSV.gz
CSV.7z
MMDB
CSV.gz
CSV.7z
CSV.gz
CSV.7z

ASN

ip_range_start, ip_range_end, autonomous_system_number, autonomous_system_organization
Database Type License Updated IPv4 IPv6 IPv4-num IPv6-num
RouteViews + ASN + DB-IP

npm version
npm version
ASN CC BY 4.0 by RouteViews and DB-IP Daily CSV
MMDB
CSV
MMDB
CSV CSV
IPtoASN

npm version
npm version
ASN PDDL by IPtoASN Daily CSV
MMDB
CSV
MMDB
CSV CSV
DB-IP Lite

npm version
npm version
ASN CC BY 4.0
by DB-IP
Monthly CSV
MMDB
CSV
MMDB
CSV CSV
GeoLite2

npm version
npm version
ASN GeoLite2 License by MaxMind Twice weekly CSV
MMDB
CSV
MMDB
CSV CSV

File formats

An explanation of each file format is provided in its own directory.

All files of a given type share the same file format; for example, you could swap one asn file for any other asn file.

Databases referenced in this project

ASN database [Update: Daily]

Created by merging 5 RIP (afrinic, apnic, arin, lacnic, ripe ncc) IP-ASN-Country database. ASN (Autonomous System Number) is a unique number assigned to an Autonomous System (AS) by the IANA.

Whois dastabase [Update: Daily]

Created by merging 5 RIP (afrinic, apnic, arin, lacnic, ripe ncc) provided WHOIS database.

GeoFeed database [Update: Daily]

Created by merging GeoFeed database from OpenGeoFeed and Collections of provider geofeed and so on.

RouteViews database [Update: every 2 hours]

We are using this database to get AS number from ipv4 address for asn. This is licensed under a CC BY 4.0, so, you must create attribution to RouteViews for using asn database.

IPtoASN database [Update: Hourly]

You can download hourly updated database in tsv format from original site. This is licensed under a Public Domain Dedication and License v1.0. There are some differences from above ASN database.

DB-IP database [Update: Monthly]

You could download and read the license from ip-to-asn-lite or ip-to-country-lite or ip-to-city-lite. Most of the AS Organization name used in asn uses ip-to-asn-lite database. We also use ip-to-asn-lite to get AS Number from ip address as a supplemental.

These database are licensed under a CC BY 4.0, so, you must create attribution to DB-IP.com for using DB-IP database.
In the case of a web application, you must include a link back to DB-IP.com on pages that display or use results from the database. You may do it by pasting the HTML code snippet into your code: <a href='https://db-ip.com/'>IP Geolocation by DB-IP</a>.
If you need better accuracy or no attribution or daily updates, please use the Commercial Version of db-ip.

GeoLite2 database [Update: Twice weekly]

GeoLite2 is created by MaxMind. The license of GeoLite2 is written in GEOLITE2_LICENSE and End User License Agreement (EULA) is written in GEOLITE2_EULA. Please carefully read the GEOLITE2_LICENSE and GEOLITE2_EULA files, if you use these database. This package comes with certain restrictions and obligations, most notably:

  • You cannot prevent the library from updating the databases.
  • You cannot use the GeoLite2 data:
    • for FCRA purposes,
    • to identify specific households or individuals.

You can read the latest version of GeoLite2 EULA. GeoLite2 databse is provided under CC BY-SA 4.0 by MaxMind, so, you must create attribution to MaxMind for using GeoLite2 database. If you need better accuracy, please use the commercial version GeoIp2.

Which database should I use?

It depends upon your use-case! We do have some simple recommendations though:

  • If you need postcodes or timezones: geolite2-city
  • If you need city data with a CC-BY Licence: dbip-city
  • If you need a country database with a Public Domain Licence: geo-whois-asn-country
  • If you need a high accuracy and wide IP range country database: geolite2-geo-whois-asn-country which is equivalent to geolite2-country for geolite2-country covered IP range and geo-whois-asn-country for the other IP range. (0.10% wider for IPv4 and 2.34% wider for IPv6 than geolite2-country at Aug. 2024)
  • If you need an ASN database: asn

Accuracy of database

Since there is no definitive information on IP addresses and country_code, it is difficult to discuss the accuracy of Public Domain data qualitatively, but it is possible to estimate the approximate accuracy by comparing it with the country information in GeoLite2 and DbIp Lite. By comparing the database in GeoLite2, which is well known for its high accuracy, with the differences in other databases, we can see that Public Domain accuracy.

Database Same Diff Empty Extra
dbip-country 96.15% 3.85% 0.00% 0.42%
asn-country 95.97% 4.00% 0.03% 0.03%
geo-asn-country 97.26% 2.71% 0.03% 0.06%
geo-whois-asn-country 96.98% 2.99% 0.03% 0.12%
iptoasn-country 76.80% 4.99% 18.21% 1.26%

Measurements were taken in 9 Oct. 2024. Because the ipv6 range is too wide, the measurements here are limited to ipv4 results. "Same" + "Diff" + "Empty" shows the GeoLite2 IP-range, and the GeoLite2 IP-range size is listed as 100%.

  • "Same" indicates the percentage of country_codes in Database that are the same as the country_code in GeoLite2.
  • "Diff" indicates the percentage of country_codes in Database that are different from GeoLite2 country_code.
  • "Empty" shows the percentage of IPs with GeoLite2 country_code but no corresponding country_code in Database.
  • "Extra" indicates the percentage of IPs with no GeoLite2 country_code listed that had a country_code listed in the Database.

We can see that for all data except iptoasn-country, the country_code matches the GeoLite2 results in more than 96% of cases. Although there is some variation in the results due to differences in update timing and the priority of the information, we believe that the Public Domain data shows a certain level of accuracy.

MMDB Libraries

If you would like to integrate MMDB files into an existing project there are several libraries that can help.

Read MMDB files

Libraries exist in many languages when using the MMDB files. There are official, Maxmind developed libraries for many popular languages: .NET, C, Java, Node.js, Perl, PHP, Python and Ruby, and third-party readers for others: Erlang, Go, Rust.

Write MMDB files

If you wish to create your own MMDB files from the CSV files (to customise their format) there are a couple of official libraries: Go and Perl (now archived). There are also some third-party options: Python and Rust.

Useful Libraries

Library Language Description Types Auto
Updates
ip-location-api Node.js Fast ip to country lookup by using in-memory database (7MB RAM) country
city
✓
country
country-extra
Browser js Ip to country lookup in browser country ✓
geocode
geocode-extra
Browser js Ip to geocode lookup in browser country
latitude
longitude
✓

Useful applications

Application Language Description Types Auto
Updates
ip_location_server Java An in-memory GRPC and HTTP server mapping IP addresses to locations (requires at least 1.5GB RAM) country
asn
city
✓
ip-location-api Go API server creating / supporting MMDB, PostgreSQL, MySQL / MariaDB and SQLite country
asn
city
✓
Ip-geo-API Go In-memory API server country ✘
IPInfoOffline Windows Desktop tool showing information about IP addresses (local data) country
asn
city
✘

Useful tools

Tool Description
ip-location-to-mmdb Basic conversion from CSV files from this database into MMDB files
mmdbmeld Create and customise MMDB files from CSV files in this database

Licences

The required licence depends upon the database which you use. Please carefully read each database licence before use.

You can use PDDL (ODC Public Domain Dedication and Licence) or CC0 (Creative Commons Zero) licensed databases without attribution for any purpose.

Support

We'd be grateful if you could link back to sapics/ip-location-db, and star this project to help others find it.