IP2Location.io R SDK (ip2locationio) is an R package for retrieving IPv4 and IPv6 geolocation, network, and IP intelligence data using the IP2Location.io API. It also supports hosted domain lookup and provides convenient R functions for getting an IP address's country, coordinates, ASN, and formatted location. The package uses the IP2Location.io Python library through R's reticulate interface.
Quick links: Get an API key · Developer documentation · R function reference · CRAN package
- IPv4 and IPv6 geolocation: Look up country, region, city, district, ZIP/postal code, latitude, longitude, and time zone.
- Network and ASN data: Retrieve available ASN, AS name, ISP, associated domain, connection speed, usage type, and other network attributes.
- Proxy and threat-related signals: Access plan-dependent proxy and security data, including available proxy indicators and fraud scores.
- Additional IP intelligence: Access eligible mobile carrier information (MCC/MNC), country metadata, advertising categories, and other supported fields.
- Hosted domain lookup: Find domains hosted on an IPv4 or IPv6 address, with optional pagination.
- Convenience lookup functions: Get just a country name, coordinates, AS name/number, or formatted city/region/country location without manually extracting each field.
- R and Python interoperability: Use the SDK from R/RStudio via
reticulateand the underlying IP2Location.io Python library.
Plan availability: Not all attributes are included in every plan, and some fields can be unavailable for particular IP addresses. Refer to the pricing page and API field reference for details.
The package provides the following functions for IP geolocation and hosted-domain lookups:
| Function | Description |
|---|---|
setApiKey(api_key) |
Configures the API key for subsequent lookups. |
lookup(ip) |
Retrieves geolocation, network, and available security information. |
lookupCountryByIP(ip) |
Returns the country name for an IP address. |
lookupCoordinateByIP(ip) |
Returns latitude and longitude. |
lookupASNByIP(ip) |
Returns the AS name and ASN. |
lookupLocationByIP(ip) |
Returns a formatted city, region, and country string. |
lookupHostedDomain(ip, page) |
Retrieves hosted domains; page is optional. |
IP2Location.io offers keyless IP geolocation queries through its REST API and a Free plan with an API key:
| API service | Keyless (no API key) | Free plan (with API key) |
|---|---|---|
| IP Geolocation API | 1,000 queries/day | 50,000 queries/month |
| Hosted Domain API | — | 50 queries/month |
- Keyless access: No registration is required for the limited IP Geolocation REST API. The allowance resets daily at 00:00 UTC. The R package examples below use an API key.
- Free plan: Sign up for an API key to use the published monthly allowances.
- Attribution: The keyless and Free offerings require attribution; see the pricing page for the current conditions.
- Paid plans: See the pricing page for higher quotas, available features, and current pricing.
For details about API authentication and rate limits, see the IP Geolocation API documentation.
- R and, optionally, RStudio for interactive development.
- Python with
pipavailable in the Python environment used by R. - The IP2Location.io Python package (
ip2location-io). - The R packages
ip2locationio,reticulate(>= 1.13), andjsonlite(>= 1.6).reticulateandjsonliteare declared package imports and are normally installed automatically with the R package. - An IP2Location.io API key for the SDK examples.
Important: This R package wraps the Python SDK. Install
ip2location-ioin the same Python environment thatreticulateuses. Installing the Python package in another environment may cause a Python module-not-found error.
In your terminal, run:
python -m pip install ip2location-ioOn systems where Python 3 is invoked as python3, use python3 -m pip install ip2location-io instead.
Option A — CRAN (recommended):
install.packages("ip2locationio")Option B — GitHub development repository:
install.packages("remotes")
remotes::install_github("ip2location/ip2location-io-r")The official Read the Docs quickstart also documents installation from GitHub using devtools::install_github().
Set the API key as an environment variable rather than placing it in the source code.
Linux / macOS terminal:
export IP2LOCATION_API_KEY='YOUR_API_KEY'Windows Command Prompt:
set IP2LOCATION_API_KEY=YOUR_API_KEYAlternatively, configure the variable in your R environment (such as a project .Renviron file that is not committed to source control). Restart your R session after modifying .Renviron.
The official Read the Docs quickstart demonstrates a geolocation lookup with the following code:
library(ip2locationio)
ip2locationio::setApiKey("YOUR_API_KEY")
result = ip2locationio::lookup("8.8.8.8")
print(result)Replace YOUR_API_KEY with your IP2Location.io API key. To run the example as a script, save it as lookup.R and use:
Rscript lookup.RThe returned fields depend on your API plan and the IP address. See the R SDK function reference for the available response fields.
Initialize the package and API key before running the following individual examples:
library(ip2locationio)
ip2locationio::setApiKey("YOUR_API_KEY")lookupCountryByIP("1.0.241.135")lookupCoordinateByIP("1.0.241.135")The result contains latitude and longitude.
lookupASNByIP("1.0.241.135")The result contains the AS name and AS number.
lookupLocationByIP("1.0.241.135")The function formats the city, region, and country into a single location string.
Security indicators depend on your API plan and may be unavailable for some addresses.
result <- lookup("8.8.8.8")
if (!is.null(result$is_proxy)) {
print(result$is_proxy)
}
if (!is.null(result$proxy)) {
print(result$proxy)
}The official Read the Docs example uses:
library(ip2locationio)
ip2locationio::setApiKey("YOUR_API_KEY")
result = ip2locationio::lookupHostedDomain("8.8.8.8")
print(result)The lookupHostedDomain() function accepts an optional page number for pagination:
lookupHostedDomain("8.8.8.8", page = 2)Hosted-domain responses can contain total_domains, page, per_page, total_pages, and domains.
If R reports that it cannot import Python module ip2locationio, check which Python environment reticulate is using:
reticulate::py_config()
reticulate::py_module_available("ip2locationio")If needed, select the Python executable containing the installed Python package before Python is initialized in your R session:
reticulate::use_python("/path/to/python", required = TRUE)Restart R after changing Python environments. Then install ip2location-io in the selected environment and retry.
- Website or application localization: Use approximate IP location to support region-aware content and reporting.
- Traffic and network analysis: Enrich IP-related records with country, coordinates, and ASN information within an R workflow.
- Security review: Consider proxy and other available signals as one part of a broader risk assessment, not as sole evidence of wrongdoing.
- Location-based reporting: Use helper functions to prepare country, geographic coordinate, or formatted-location outputs for R analysis.
- Network research: Investigate AS information and domain names hosted on an IP address.
- R SDK quickstart and sample codes
- R SDK function reference
- CRAN package and reference manual
- Python SDK dependency
- IP2Location.io API plans and query limits
- IP Geolocation API authentication and rate limits
- Report an SDK issue or request a feature
- API and account support
Licensed under the MIT License. See LICENSE.TXT.