Advertisement
Guest User

Untitled

a guest
Jun 21st, 2022
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export async function script1({hostname}: {
  2.   hostname: string
  3. }): Promise<{
  4.   pass: boolean;
  5.   error?: string;
  6. }> {
  7.   const nameservers = await dns(hostname, "NS");
  8.   if (!nameservers.length) {
  9.     return {
  10.       pass: false,
  11.       error: "No nameservers found. Could be an issue with the DNS server."
  12.     };
  13.   }
  14.   const failed = [];
  15.   for (let i = 0; i < nameservers.length; ++i) {
  16.     const server = nameservers[i].value;
  17.     const serverA = await dns(server, "A");
  18.     if (!serverA.length) {
  19.       return {
  20.         pass: false,
  21.         error: `No A record found for nameserver ${server}.`
  22.       };
  23.     }
  24.     const nsIp = serverA[0].value;
  25.     const records = await dns(hostname, "A", nsIp);
  26.     if (!records.length) {
  27.       failed.push(server);
  28.     }
  29.   }
  30.   if (failed.length) {
  31.     return {
  32.       pass: false,
  33.       error: `The following nameservers did not respond with an A-record for ${hostname}: ${failed.join(
  34.         ", "
  35.       )}`
  36.     };
  37.   }
  38.   return {
  39.     pass: true
  40.   };
  41. }
  42.  
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement