On Google Spreadsheet, how do you call the CIty, Country of an IP?

大城市里の小女人 提交于 2020-01-12 23:27:12

问题


I would like to know if there is a formula/script one could use on Google Spreadsheet to obtain the City,Location of an array of IP addresses.

i.e lets imagine that each cell on column A has 100 IP addresses, what formula/script should I use on column B to get the respective city and location?


回答1:


After some digging I've figured out how to do this.

  1. Copy the import_json_appsscript.js script on https://gist.github.com/chrislkeller/5719258. This will be the script that will create the ImportJSON() function to a Google spreadsheet

  2. Go to Google spreadsheet, on the menu bar got to Tools > Script Editor

  3. Copy paste import_json_appsscript.js into the Script Editor and save it, Double check that you can see the ImportJSON() function on the Select function drop down menu.

  4. On the Spreadsheet use function =ImportJSON(url, query, options), for example =ImportJSON("http://freegeoip.net/json/75.148.30.137", "/city", "noHeaders") to retrieve Baltimore from the FreeGeoIP call.

Hope that helps, it certainly answers my question.




回答2:


If you are looking to write a macro of some sort, you could consider using freegeoip.net which lets you make a simple restful call to get back data in a variety of formats.

http://freegeoip.net/

For example, a call to find the location for the ip address 75.148.30.137 would look like this:

http://freegeoip.net/json/75.148.30.137

Also, here is a link to Google's documentation on how to make rest calls in a Google app:

https://developers.google.com/apps-script/guides/services/external

Good luck.




回答3:


I recently implemented the same scenario with IP Stack API. API will return a Json response with all geolocation details.

for(var i in IPs)
{
  var url = 'http://api.ipstack.com/'+ IPs[i][0]+ '?access_key=access_key&output=json';
  var httpResponse = UrlFetchApp.fetch(url);
  var rspns = httpResponse.getResponseCode();
  //deal with this response
}

Read full google sheet implementation from here; Find Geo location of Multiple IP addresses via Google Apps Script



来源:https://stackoverflow.com/questions/20430721/on-google-spreadsheet-how-do-you-call-the-city-country-of-an-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!