On Google Spreadsheet, how do you call the CIty, Country of an IP?
After some digging I've figured out how to do this.
Copy the
import_json_appsscript.js
script on https://gist.github.com/chrislkeller/5719258. This will be the script that will create theImportJSON()
function to a Google spreadsheetGo to Google spreadsheet, on the menu bar got to Tools > Script Editor
Copy paste
import_json_appsscript.js
into the Script Editor and save it, Double check that you can see theImportJSON()
function on the Select function drop down menu.On the Spreadsheet use function =ImportJSON(url, query, options), for example
=ImportJSON("http://freegeoip.net/json/75.148.30.137", "/city", "noHeaders")
to retrieveBaltimore
from the FreeGeoIP call.
Hope that helps, it certainly answers my question.
The easiest way to do this via an external service. IPInfo supports requesting a single field, so you can actually do this without using any addon (via IMPORTDATA
function). Quick example:
For country: =IMPORTDATA("https://ipinfo.io/" & A1 & "/country")
For city: =IMPORTDATA("https://ipinfo.io/" & A1 & "/country")
Here A1
is IP address cell.
To avoid getting rate limited, you can register for a free account (50k monthly requests) and use a token.
Disclaimer: I work at IPInfo.
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.
For example, a call to find the location for the ip address 75.148.30.137would 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.