Created
May 12, 2022 23:55
-
-
Save jchrisfarris/dc96f3ebb6f078d34c39878f045aeada to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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