maxmind: Geolocate IP Addresses through MaxMind Databases

Description Usage Arguments Details Examples

View source: R/maxmind.R

Description

MaxMind does a set of proprietary geolocation databases - they're pretty accurate! maxmind provides a connector to MaxMind services.

Usage

1
2
3
4
5
maxmind(
  ips,
  file,
  fields = c("continent_name", "country_name", "country_code")
)

Arguments

ips

a character vector of IP addresses (IPv4 and IPv6 both work)

file

the full path to the .mmdb file you want to query.

fields

the fields you want to retrieve - a vector of any combination of:

  • continent_name: the English-language name of the continent. Requires a country or city database.

  • country_name: the English-language name of the country. Requires a country or city database.

  • country_code: the ISO code of the country. Requires a country or city database.

  • region_name: the English-language name of the region. Requires a city database.

  • city_name: the English-language name of the city. Requires a city database.

  • postcode: The approximate post/ZIP code. Requires a city database.

  • city_geoname_id: a unique ID representing a city. Requires a city database.

  • timezone: the tzdata-compatible time zone. Requires a city database.

  • longitude: longitude of location. Requires a city database.

  • latitude: latitude of location. Requires a city database.

  • isp: name of ISP. Requires an ISP database.

  • organization: name of organization. Requires an ISP database.

  • asn: Autonomous System Number. Requires an ISP database.

  • aso: Autonomous System Organization. Requires an ISP database.

  • connection: the type of internet connection. Requires a connection type/netspeed database.

Details

geolookup uses the MaxMind GeoIP2 databases to geolocate IP addresses, retrieving any of the data listed in fields. Different fields are appropriate for different provided files; the connection type databases, for example, contain connection types and nothing else, while the city- and country-level files don't contain connection types at all.

rgeolocate ships with a country-level database (accessing it can be seen in the examples). If you need city-level data, or other MaxMind databases, you'll need to download the .mmdb files yourself - for CRAN and/or copyright reasons, depending, we cannot include them.

In the event that the file provided does not have the field you have requested (or the IP address does not have an entry for that field), NA will be returned instead. In the event that the IP address doesn't have an entry in the file at all, NA will be returned for every field.

Examples

1
2
3
# An example, using the country-level dataset shipped with rgeolocate.
file <- system.file("extdata","GeoLite2-Country.mmdb", package = "rgeolocate")
results <- maxmind("196.200.60.51", file, "country_code")

rgeolocate documentation built on Dec. 20, 2021, 9:06 a.m.