Learn R Programming

rgeolocate (version 0.5.0)

ip_api: Geolocate IP Addresses Through ip-api.com

Description

ip_api consumes a vector of IP addresses and geolocates them via http://ip-api.com{ip-api.com}.

Usage

ip_api(ip_addresses, as_data_frame = TRUE, delay = FALSE)

Arguments

ip_addresses
a character vector of IP addresses
as_data_frame
whether to return the results as a data.frame or not. Set to TRUE by default.
delay
whether or not to delay each request by 100ms. ip-api.com has a maximum threshold of 2,500 requests a minute; if you're parallelising calls, you might run into this. delay allows you to set a delay between requests, taking advantage of parall

Value

  • either a data.frame or a list of vectors. If an IP cannot be geolocated, it will provide an error message: see the examples for field names and examples of each possible output.

Examples

Run this code
#Valid, data.frame output
result <- ip_api("2607:FB90:426:DC1D:CFC4:4875:8BC2:4D93")

#Invalid, data.frame output
result <- ip_api("argh")

#Valid list output
result <- ip_api("2607:FB90:426:DC1D:CFC4:4875:8BC2:4D93", as_data_frame = FALSE)

#Invalid list output
result <- ip_api("argh", as_data_frame = FALSE)

Run the code above in your browser using DataLab