Yesterday, I needed to get current results for the “Nameservers” for a batch of about 400 domains. To look each domain up manually would take forever—even using dig from the Linux terminal like I do it. Plus, I wanted to record the results in a spreadsheet for reference and for some quick analysis.
I had the domains in a Google Sheet already, so it was just a matter of spinning up a quick Google Apps Script to perform the DNS lookups and return the results to the Google Sheet.
Naturally, I turned to Google to help with this situation and stumbled across this piece by Alex Miller on Medium that suggested a method for doing exactly what I wanted to do. Unfortunately, I had some trouble with Alex’s code, which relied upon queries to a Google DNS service.
Thankfully, he linked out to a useful Stackoverflow thread which provides quite a few code options for performing DNS lookups in Google Sheets. It’s clear from the history of the responses that various public DNS resolvers have come and gone in the ~6 years since the question was originally asked. Naturally, changes in Google Apps script have also affected the utility of some of the scripts in the replies.
The Solution: Using Cloudflare’s 1.1.1.1 DNS Resolver with Google Sheets
I tested some code that appears in this reply to the Stackoverflow thread linked above, but had some difficulty at first. No matter what I added to my formula for “record type,” the query returned an IP address corresponding to the “A record” for the domain.
That led me to find the code (below) from Cloudflare’s 1.1.1.1 Docs:
function NSLookup(type, domain) {
if (typeof type == 'undefined') {
throw new Error('Missing parameter 1 dns type');
}
if (typeof domain == 'undefined') {
throw new Error('Missing parameter 2 domain name');
}
type = type.toUpperCase();
var url = 'https://cloudflare-dns.com/dns-query?name=' + encodeURIComponent(domain) + '&type=' + encodeURIComponent(type);
var options = {
muteHttpExceptions: true,
headers: {
accept: "application/dns-json"
}
};
var result = UrlFetchApp.fetch(url, options);
var rc = result.getResponseCode();
var resultText = result.getContentText();
if (rc !== 200) {
throw new Error(rc);
}
var errors = [
{ 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
];
var response = JSON.parse(resultText);
if (response.Status !== 0) {
return errors[response.Status].name;
}
var outputData = [];
for (var i in response.Answer) {
outputData.push(response.Answer[i].data);
}
var outputString = outputData.join(',');
return outputString;
}I’m not 100% sure how close the two code snippets are to one another (they may be identical, I just didn’t check). Once I implemented the code from Cloudflare, though, the issue with only receiving the “A” record result persisted.
Here’s what I learned about getting it to work.
The mistake I was making was that I was manually adding the record type to the formula I was typing in Google Sheets. For example:
=NSLookup(NS,A2)
where “NS” is the record type I was hoping to retrieve and “A2” is the cell containing the domain name.
Once I added a column for the record type, everything worked. My updated formula reads:
=NSLookup(D2,A2)
where “D2” is the cell containing the record type.
In hindsight, I probably could have just wrapped the NS in quotes and my first attempt at this formula probably would have worked.
In any case, this worked beautifully. I was able to retrieve the Nameserver records for more than 400 domains in a matter of just a few seconds, and then do some quick “conditional formatting” to easily note the specific situations I was trying to track down.
One thing that occurred, though, was that Cloudflare’s DNS resolver returned refused for maybe 20 or 30 of the domains. I suspect this was a result of throttling. I was able to force the query to run again by modifying the “record type” value, which triggered Google Sheets to notice the formula reference was no longer current, and the script ran again. Changing the record type back to “NS” in the corresponding cell caused the query to return the proper result for the “Nameserver” record as expected.
I hope this helps someone! Feel free to ping me in the comments if you have questions or thoughts. Cheers!

Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
You’ve built a lot of trust through your consistency.
I wasn’t expecting to learn so much from this post!
This helped clarify a lot of questions I had.
Clear, concise, and useful — exactly what I needed today.
You really know how to connect with your readers.
You’ve sparked my interest in this topic.
This was easy to follow, even for someone new like me.
This is one of the best explanations I’ve read on this topic.
Thanks for making this so reader-friendly.
Keep writing! Your content is always so helpful.
The way you write feels personal and authentic.
Your breakdown of the topic is so well thought out.
I wish I had read this sooner!
This is now one of my favorite blog posts on this subject.
I wish I had read this sooner!
I learned something new today. Appreciate your work!
I appreciate the real-life examples you added. They made it relatable.
I always look forward to your posts. Keep it coming!
Hi, how have you been lately?
What a helpful and well-structured post. Thanks a lot!
This was really well done. I can tell a lot of thought went into making it clear and user-friendly. Keep up the good work!
You made some excellent points here. Well done!
Thank you for sharing this! I really enjoyed reading your perspective.
This gave me a lot to think about. Thanks for sharing.
Excellent work! Looking forward to future posts.
Posts like this are why I keep coming back. It’s rare to find content that’s simple, practical, and not full of fluff.
The way you write feels personal and authentic.
This gave me a whole new perspective. Thanks for opening my eyes.
You write with so much clarity and confidence. Impressive!
I love how clearly you explained everything. Thanks for this.
Your tips are practical and easy to apply. Thanks a lot!
You always deliver high-quality information. Thanks again!
Your passion for the topic really shines through.
You made some excellent points here. Well done!
I always look forward to your posts. Keep it coming!
You bring a fresh voice to a well-covered topic.
Thank you for covering this so thoroughly. It helped me a lot.
???????????????????????????????????????????????????????????????????1199.pw
You explained it in such a relatable way. Well done!
Your writing always inspires me to learn more.
I’ll definitely come back and read more of your content.
This is one of the best explanations I’ve read on this topic.
Great information shared.. really enjoyed reading this post thank you author for sharing this post .. appreciated
Turkey travel packages Ashley S. – Pakistan http://www.tecnoac.com/?p=56090
I love how practical and realistic your tips are.
This was a great reminder for me. Thanks for posting.
I appreciate the real-life examples you added. They made it relatable.
Thanks for making this so reader-friendly.
You’ve clearly done your research, and it shows.
ukraine travel packages Emma J. The Bosphorus dinner cruise was full of great food and live entertainment. https://tr.linkedin.com/company/travalshopbooking
You write with so much clarity and confidence. Impressive!
I’ve gained a much better understanding thanks to this post.
This was easy to follow, even for someone new like me.
I feel more confident tackling this now, thanks to you.
Really insightful post — Your article is very clearly written, i enjoyed reading it, can i ask you a question? you can also checkout this newbies in classied. iswap24.com. thank you
Excellent breakdown, I like it, nice article. I completely agree with the challenges you described. For our projects we started using Listandsell.us and experts for our service, Americas top classified growing site, well can i ask zou a question regarding zour article?
I like how you presented both sides of the argument fairly.
Yorumlara bakmadan geçmeyin: https://www.beylikduzukorsantaksi.org/ – Beylikdüzü korsan taksi
Her zaman tercih etti?im Beylikdüzü korsan taksi servisi bu.
???????????????????????????????????????????????????????????????????1199.pw
Excellent breakdown, I like it, nice article. I completely agree with the challenges you described. For our projects we started using Listandsell.us and experts for our service, Americas top classified growing site, well can i ask zou a question regarding zour article?
Really insightful post — Your article is very clearly written, i enjoyed reading it, can i ask you a question? you can also checkout this newbies in classied. iswap24.com. thank you
This topic really needed to be talked about. Thank you.
I enjoyed your perspective on this topic. Looking forward to more content.
Pretty! This has been a really wonderful post. Many thanks for providing these details.
This was easy to follow, even for someone new like me.
Great article! I’ll definitely come back for more posts like this.
I’m definitely going to apply what I’ve learned here.
This was easy to follow, even for someone new like me.
What an engaging read! You kept me hooked from start to finish.
Thanks for making this easy to understand even without a background in it.
I appreciate the real-life examples you added. They made it relatable.
This topic really needed to be talked about. Thank you.
Thank you for offering such practical guidance.
Your articles always leave me thinking.
Keep educating and inspiring others with posts like this.
Thanks for taking the time to break this down step-by-step.
I love how practical and realistic your tips are.
Thank you for making this topic less intimidating.
I’ve gained a much better understanding thanks to this post.
Thanks for addressing this topic—it’s so important.
This was easy to follow, even for someone new like me.
This was incredibly useful and well written.
Very relevant and timely content. Appreciate you sharing this.
Very relevant and timely content. Appreciate you sharing this.
This gave me a whole new perspective on something I thought I already understood. Great explanation and flow!
It’s refreshing to find something that feels honest and genuinely useful. Thanks for sharing your knowledge in such a clear way.
I enjoyed every paragraph. Thank you for this.
I learned something new today. Appreciate your work!
You’ve built a lot of trust through your consistency.
The way you write feels personal and authentic.
I appreciate how genuine your writing feels. Thanks for sharing.
Your tips are practical and easy to apply. Thanks a lot!
This gave me a whole new perspective. Thanks for opening my eyes.
I’ll definitely come back and read more of your content.
I feel more confident tackling this now, thanks to you.
This was a great reminder for me. Thanks for posting.
Your writing always inspires me to learn more.
I appreciate the real-life examples you added. They made it relatable.
Your content never disappoints. Keep up the great work!
Your passion for the topic really shines through.
Your tips are practical and easy to apply. Thanks a lot!
I’m definitely going to apply what I’ve learned here.
I’ve read similar posts, but yours stood out for its clarity.
I’ll definitely come back and read more of your content.
Such a thoughtful and well-researched piece. Thank you.
I enjoyed every paragraph. Thank you for this.
Very useful tips! I’m excited to implement them soon.
You really know how to connect with your readers.
I’ve bookmarked this post for future reference. Thanks again!
You made some excellent points here. Well done!
What a helpful and well-structured post. Thanks a lot!
This was really well done. I can tell a lot of thought went into making it clear and user-friendly. Keep up the good work!
Thank you for being so generous with your knowledge.
Such a refreshing take on a common topic.
This was easy to follow, even for someone new like me.
I like how you presented both sides of the argument fairly.
I appreciate how genuine your writing feels. Thanks for sharing.
This gave me a whole new perspective. Thanks for opening my eyes.
Keep educating and inspiring others with posts like this.
Great post! I’m going to share this with a friend.
Great article! I’ll definitely come back for more posts like this.
This was so insightful. I took notes while reading!
This was a very informative post. I appreciate the time you took to write it.
Keep writing! Your content is always so helpful.
Thank you for covering this so thoroughly. It helped me a lot.
I like how you kept it informative without being too technical.
This is now one of my favorite blog posts on this subject.
I like how you kept it informative without being too technical.
I agree with your point of view and found this very insightful.
Thank you for covering this so thoroughly. It helped me a lot.
You’ve sparked my interest in this topic.
Your content never disappoints. Keep up the great work!
Excellent work! Looking forward to future posts.
I enjoyed your perspective on this topic. Looking forward to more content.
I wasn’t expecting to learn so much from this post!
Thank you for putting this in a way that anyone can understand.
Great article! I’ll definitely come back for more posts like this.
I’ve gained a much better understanding thanks to this post.
Such a thoughtful and well-researched piece. Thank you.
You have a real gift for explaining things.
Excellent work! Looking forward to future posts.
Your passion for the topic really shines through.
The way you write feels personal and authentic.
I appreciate the real-life examples you added. They made it relatable.
Excellent work! Looking forward to future posts.
You’ve built a lot of trust through your consistency.
Keep writing! Your content is always so helpful.
I really needed this today. Thank you for writing it.
This was so insightful. I took notes while reading!
I really needed this today. Thank you for writing it.
This content is gold. Thank you so much!
Useful and well-structured. Looking forward to more posts from you.
I appreciate your unique perspective on this.
This helped clarify a lot of questions I had.
I never thought about it that way before. Great insight!
I hadn’t considered this angle before. It’s refreshing!
I learned something new today. Appreciate your work!
Your articles always leave me thinking.
Such a refreshing take on a common topic.
Your writing style makes complex ideas so easy to digest.
Great article! I’ll definitely come back for more posts like this.
What a great resource. I’ll be referring back to this often.
This gave me a whole new perspective. Thanks for opening my eyes.
This made me rethink some of my assumptions. Really valuable post.
I enjoyed every paragraph. Thank you for this.
Thanks for addressing this topic—it’s so important.
I appreciate the honesty and openness in your writing.
It’s great to see someone explain this so clearly.
I appreciate the depth and clarity of this post.
Your writing always inspires me to learn more.
Thanks for making this easy to understand even without a background in it.
You’re doing a fantastic job with this blog.
Nice blog here Also your site loads up fast What host are you using Can I get your affiliate link to your host I wish my web site loaded up as quickly as yours lol
Thank you for covering this so thoroughly. It helped me a lot.
This gave me a whole new perspective on something I thought I already understood. Great explanation and flow!
This post cleared up so many questions for me.
I enjoyed your perspective on this topic. Looking forward to more content.
Great job simplifying something so complex.
You’ve done a great job with this. I ended up learning something new without even realizing it—very smooth writing!
I learned something new today. Appreciate your work!
Such a thoughtful and well-researched piece. Thank you.
You always deliver high-quality information. Thanks again!
Posts like this are why I keep coming back. It’s rare to find content that’s simple, practical, and not full of fluff.
You’re doing a fantastic job with this blog.
I like how you presented both sides of the argument fairly.
This was very well laid out and easy to follow.
You bring a fresh voice to a well-covered topic.
Your content never disappoints. Keep up the great work!
I wasn’t expecting to learn so much from this post!
Such a refreshing take on a common topic.
Such a refreshing take on a common topic.
Thanks for including real user stories — very relatable.
This topic is usually confusing, but you made it simple to understand.
Thanks for addressing this topic—it’s so important.
Thank you for making this topic less intimidating.
I love the clarity in your writing.
Thanks for making this easy to understand even without a background in it.
I’ll be sharing this with a few friends.
Nice article! I especially liked the actionable checklist.
Thanks for sharing your knowledge. This added a lot of value to my day.
Great points, well supported by facts and logic.
?????????
You have a real gift for explaining things.
Your thoughts are always so well-organized and presented.
This is exactly the kind of content I’ve been searching for.
I never thought about it that way before. Great insight!
I’m definitely going to apply what I’ve learned here.
Your thoughts are always so well-organized and presented.
Your thoughts are always so well-organized and presented.
You really know how to connect with your readers.
poker
Your advice is exactly what I needed right now.