StaticDNSAdder.rsc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. :local fileName "";
  2. :local fileContents "";
  3. :local lineArray "";
  4. :local dnsRec "";
  5. :local dnsIP "";
  6. :local dnsTTL "";
  7. :local dnsRecTotal 0;
  8. :foreach tDNsFile in=[/file find name~".1984t"] do={
  9. :local contentLen;
  10. :local lineEnd 0;
  11. :local line "";
  12. :local lastEnd 0;
  13. :log warning "";
  14. :log warning "";
  15. :log warning ".1984t files found: starting adding process";
  16. :set fileName [/file get $tDNsFile name];
  17. :log warning ("Processing file: " . $fileName);
  18. :set fileContents [/file get $tDNsFile contents];
  19. :set contentLen [:len $fileContents];
  20. :while ([:typeof $lineEnd] != "nil" && $lineEnd < $contentLen) do={
  21. :set lineEnd [:find $fileContents "\n" $lastEnd ];
  22. :set line [:pick $fileContents $lastEnd $lineEnd];
  23. :set lastEnd ($lineEnd + 1);
  24. :if (line != "" && [:len $line] > 0) do={
  25. :set lineArray [:toarray $line]
  26. :if ([:typeof $lineArray] = "array" && [:len $lineArray] > 0) do={
  27. :set dnsRec [:pick $lineArray 0];
  28. :set dnsIP [:pick $lineArray 1];
  29. :set dnsTTL [:pick $lineArray 2];
  30. :log warning ("Adding static DNS record: " . $line);
  31. /ip dns static add address=$dnsIP name=$dnsRec ttl=$dnsTTL;
  32. :set dnsRecTotal ($dnsRecTotal + 1);
  33. } else={
  34. :log warning "Can not cast DNS record $line to array, skipping"
  35. }
  36. } else={
  37. :log warning "DNS record is empty, skipping"
  38. }
  39. }
  40. :log warning ("Removing " . $fileName);
  41. /file remove $fileName;
  42. :log warning "";
  43. :log warning "";
  44. }
  45. :log warning "Total DNS recs added: $dnsRecTotal";