DNS Lookup from ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2023 07:04 AM
I have a script include where I am assigning a name to server before it gets to vRA for provisioning. I want to do a DNS lookup to see if a host with that name already exists or not. If not existing then only wants to move forward with provisioning a server. What options are available to do DNS lookup from SN within script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2023 08:52 AM
Hi @deesha ,
I trust you are doing great.
To perform a DNS lookup from a ServiceNow (SN) script include, you can use the "GlideRecord" API to query a DNS server. Here's an example code snippet to achieve this:
// Create a new GlideRecord object to query the DNS server
var dnsGR = new GlideRecord('discovery_dns_server');
dnsGR.addQuery('name', 'YOUR_DNS_SERVER_NAME'); // Replace with your DNS server name
dnsGR.query();
// If DNS server found, query it for the hostname
if (dnsGR.next()) {
var ip = gs.lookupHost(hostname);
if (ip == null) {
gs.log("Hostname not found in DNS");
} else {
gs.log("Hostname found in DNS");
}
} else {
gs.log("DNS server not found");
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi