rgeolocate错误--每个IP地址的国家。

问题描述 投票:0回答:1

我无法让rgeolocate正常工作。我需要能够确定一个IP地址是否在澳大利亚。

我有一个csv中的IP地址列表。然而,我提供了下面的示例代码,却得到以下错误。

Error in maxmind_(ips, normalizePath(path.expand(file)), fields) : 
  Not compatible with STRSXP: [type=list].

我在谷歌上搜索了一下解决方法,但到目前为止还没有找到任何解决方法,如果有人知道解决方法,我会非常感激。

rgeolocate软件包已经成功下载,GeoLite2-Country.mmdb似乎在extdata文件夹中它应该在的位置。

library(rgeolocate)

ip_lst <-
  data.frame(
    "ip_lst" = c(
      "27.33.27.39",
      "203.219.204.84",
      "203.5.106.68",
      "180.150.74.11",
      "193.116.238.48",
      "1.157.7.35",
      "61.69.150.57",
      "155.143.204.211"
    )
  )

file <- system.file("extdata","GeoLite2-Country.mmdb", package = "rgeolocate")
results <- maxmind(ip_lst, file, c("continent_name", "country_code", "country_name"))
results

我已经尝试了多个版本的Maxmind代码,但都没有成功。预先感谢任何帮助。

r geolocation ip-address maxmind
1个回答
1
投票

你已经创建了一个名为 ip_lst 包含一个名为 ip_lst,这并没有错,但可能会让人感到困惑。这里的问题是 maxind 函数期待一个字符 矢量但你提供的是一个数据框架。所以,下面的操作应该是可行的。

maxmind(ip_lst$ip_lst, file, c("continent_name", "country_code", "country_name"))

  continent_name country_code   country_name
1        Oceania           AU      Australia
2        Oceania           AU      Australia
3        Oceania           AU      Australia
4        Oceania           AU      Australia
5         Europe           GB United Kingdom  # <-- Not an Aussie 8(
6        Oceania           AU      Australia
7        Oceania           AU      Australia
8        Oceania           AU      Australia
© www.soinside.com 2019 - 2024. All rights reserved.