1.1.1.1 works directly inside Google Sheets. To get started, create aGoogle Function ↗ with the following code:
functionNSLookup(type,domain,useCache=false,minCacheTTL=30){if (typeoftype=='undefined'){thrownewError('Missing parameter 1 dns type');}if (typeofdomain=='undefined'){thrownewError('Missing parameter 2 domain name');}if (typeofuseCache!="boolean"){thrownewError('Only boolean values allowed in 3 use cache');}if (typeofminCacheTTL!="number"){thrownewError('Only numeric values allowed in 4 min cache ttl');}type=type.toUpperCase();domain=domain.toLowerCase();letcache= null;if (useCache){// Cache key and hashcacheKey=domain+"@"+type;cacheHash=Utilities.base64Encode(cacheKey);cacheBinKey="nslookup-result-"+cacheHash;cache=CacheService.getScriptCache();constcachedResult=cache.get(cacheBinKey);if (cachedResult!=null){returncachedResult;}}consturl='https://cloudflare-dns.com/dns-query?name='+encodeURIComponent(domain)+'&type='+encodeURIComponent(type);constoptions={muteHttpExceptions: true,headers:{accept:"application/dns-json"}};constresult=UrlFetchApp.fetch(url,options);constrc=result.getResponseCode();constresultText=result.getContentText();if (rc!==200){thrownewError(rc);}consterrors= [{ name:"NoError", description:"No Error"},// 0{ name:"FormErr", description:"Format Error"},// 1{ name:"ServFail", description:"Server Failure"},// 2{ name:"NXDomain", description:"Non-Existent Domain"},// 3{ name:"NotImp", description:"Not Implemented"},// 4{ name:"Refused", description:"Query Refused"},// 5{ name:"YXDomain", description:"Name Exists when it should not"},// 6{ name:"YXRRSet", description:"RR Set Exists when it should not"},// 7{ name:"NXRRSet", description:"RR Set that should exist does not"},// 8{ name:"NotAuth", description:"Not Authorized"}// 9];constresponse=JSON.parse(resultText);if (response.Status!==0){returnerrors[response.Status].name;}constoutputData= [];letcacheTTL=0;for (constiinresponse.Answer){outputData.push(response.Answer[i].data);constttl=response.Answer[i].TTL;cacheTTL=Math.min(cacheTTL||ttl,ttl);}constoutputString=outputData.join(',');if (useCache){cache.put(cacheBinKey,outputString,Math.max(cacheTTL,minCacheTTL));}returnoutputString;}When you feed the functionNSLookup a record type and a domain, you will get a DNS record value in the cell you calledNSLookup.
To limit the number of DNS lookups and speed up the results (especially in larger Google Sheets), you can cache the returned DNS record value. Both the cache usage and the cache TTL can be controlled in arguments 3 and 4, respectively.
Supported DNS record types
AAAAACAACNAMEDSDNSKEYMXNSNSECNSEC3RRSIGSOATXT
For example, typing:
NSLookup(B1, B2)Or - depending on your regional settings - you may have to use this formula:
NSLookup(B1; B2)
Returns
198.41.214.162, 198.41.215.162
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark