[英]ruby: given an ip address, find out the City and State
我已經搜索了大約十分鍾,還沒有找到一個簡單的代碼示例。
基本上,我正在尋找這樣的東西:
puts Geocoder.lookup_location_by_ip("76.95.251.102")
result California, USA
因此,紅寶石方法可以將IP地址解碼到其州(州)。
這些步驟是:
使用以下方法安裝地址解析器:
gem install geocoder
在Ruby腳本中使用:
require "geocoder" puts Geocoder.address('76.95.251.102') #Change the ip address accordingly.
運行腳本以獲取城市,州,郵政編碼,國家/地區。
# => Bellflower, CA 90706, United States
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.