Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchrisfarris/dc96f3ebb6f078d34c39878f045aeada to your computer and use it in GitHub Desktop.
Save jchrisfarris/dc96f3ebb6f078d34c39878f045aeada to your computer and use it in GitHub Desktop.
function WHOIS(ipaddr) {
var url = 'https://rdap-bootstrap.arin.net/bootstrap/ip/' + ipaddr
Logger.log(url)
var options = {
muteHttpExceptions: true,
followRedirects: true,
headers: {
accept: "application/json"
}
};
var result = UrlFetchApp.fetch(url, options);
var rc = result.getResponseCode();
// Logger.log(result.getHeaders());
if (rc == 302) {
var new_url = result.getHeaders()['Location']
Logger.log("Following 302 to " + new_url)
result = UrlFetchApp.fetch(new_url, options);
rc = result.getResponseCode();
}
if (rc !== 200) {
Logger.log("Got error " + rc)
throw new Error(rc);
}
var resultText = result.getContentText();
var response = JSON.parse(resultText);
var owner = "Undefined"
try {
owner = response['entities'][0]['vcardArray'][1][1][3]
} catch (error) {
owner = response['name']
}
// Logger.log(JSON.stringify(owner))
return owner;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment