To determine the Autonomous System (AS) CIDR for an IP address using IP2Location.io in R, you can use the IP2Location.io API to retrieve geolocation and related data.
install.packages(c("httr", "jsonlite"))
library(httr)
library(jsonlite)
ip = "8.8.8.8"
key = "YOUR_API_KEY"
res <- GET("https://api.ip2location.io/",
query = list(format = "json", ip = ip, key = key))
if (res$status_code == 200) {
raw <- rawToChar(res$content)
data <- fromJSON(raw)
if (!is.null(data$as_info)) {
print(paste0("The AS CIDR for IP ", ip, " is ", data$as_info$as_cidr, "."))
} else{
print("ERROR: The as_cidr field requires a paid subscription to the Security plan.")
}
} else if ((res$status_code == 400) || (res$status_code == 401)) {
raw <- rawToChar(res$content)
data <- fromJSON(raw)
if (!is.null(data$error)) {
print(paste0("ERROR: ", data$error$error_message))
} else {
print(data)
}
} else {
print(paste0("ERROR: ", res$status_code))
}
This script will output the AS CIDR of specified IP address. Make sure to replace 8.8.8.8 with the IP address you want and replace YOUR_API_KEY to your own API key.
Empower your applications with accurate IP geolocation information now.
Try It for Free