Last active
September 12, 2018 05:48
-
-
Save mogsdad/ece531531e0ef5dc355d to your computer and use it in GitHub Desktop.
NSLookup - Google Sheets custom function to Perform a Network Service Lookup, using StatDNS API. From "Nslookup or dig in Google App Script" (http://stackoverflow.com/a/30610580/1677912).
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
/** | |
* Perform a Network Service Lookup, using StatDNS API. | |
* | |
* @param {"google.com"} dn A well-formed domain name to resolve. | |
* @return {String} Resolved IP address | |
* @customfunction | |
*/ | |
function NSLookup(dn) { | |
// From gist.github.com/mogsdad/ece531531e0ef5dc355d | |
var url = "http://api.statdns.com/%FQDN%/a".replace("%FQDN%",dn); | |
var result = UrlFetchApp.fetch(url,{muteHttpExceptions:true}); | |
var rc = result.getResponseCode(); | |
var response = JSON.parse(result.getContentText()); | |
if (rc !== 200) { | |
throw new Error( response.message ); | |
} | |
var ip = response.answer[0].rdata; | |
return ip; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Getting an error for line 11