use dns.getservers in javascript

To use dns.getServers() in javascript, you need to require the dns module first.

index.tsx
const dns = require('dns');
28 chars
2 lines

Once you have the dns module, you can call the getServers() method to get an array of IP addresses for the DNS servers that the system is currently using.

index.tsx
const dns = require('dns');
const dnsServers = dns.getServers();

console.log(dnsServers);
91 chars
5 lines

This will output something like:

index.tsx
[ '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220' ]
61 chars
2 lines

This means that the system is currently using Google's public DNS servers (8.8.8.8 and 8.8.4.4) and OpenDNS servers (208.67.222.222 and 208.67.220.220).

related categories

gistlibby LogSnag