IP2Location provides proprietary databases for IP geolocation;
this function acts as a binding to them, letting you efficiently geolocate
a vector of IP addresses to retrieve various values (much like maxmind
).
Note that depending on the database type you have, certain fields may or may not be
available.
ip2location(
ips,
file,
fields = c("country_code", "country_name"),
use_memory = TRUE
)
A character vector of IP addresses.
The path to an IP2Location binary database. One is included in the package (see the examples below); full datasets can be purchased, and sample ones downloaded, at the ip2location website.
Which pieces of metadata to retrieve for each IP address. Options are:
country_code: the ISO code of the country.
country_name: the English-language name of the country.
region_name: the English-language name of the region.
city: the English-language name of the city.
isp: The Internet Service Provider
lat: The latitude.
long: The longitude.
domain: The domain name associated with the IP (if any).
zip_code: The Zip Code or Post Code or national equivalent.
timezone: The timezone, in the format +02:00/-03:00 from UTC.
netspeed: The internet connection class of the IP address.
international_code: The international dialing code.
area_code: The local dialing code.
station_code: The identifying code of the nearest weather station.
station_name: The name of the nearest weather station.
mcc: The Mobile Country Code, which identifies mobile stations.
mnc: The Mobile Network Code, which (with MCC) uniquely identifies the mobile carrier.
mobile_brand: The commercial brand associated with the mobile carrier.
elevation: The elevation of the location above sea level, in meters.
usage_type: The type of organisation or purpose behind the IP; see the list here.
Note that these fields may or may not be available depending on your database type.
Whether to cache the binary in memory or not. Caching it drastically increases the speed of geolocation, but may be too much for very old machines. Set to TRUE by default.
A data.frame containing the geolocation metadata about ips
; missing
values are represented by NA
.
maxmind
, which uses MaxMind proprietary databases to get similar
information.
# NOT RUN {
file <- system.file("extdata","ip2_sample.bin", package = "rgeolocate")
example_ip <- "2A04:0000:0000:0000:0000:0000:0000:0000"
ip2location(example_ip, file, c("country_code", "country_name", "region", "city"))
# }
Run the code above in your browser using DataLab