Advertisement
ucomesdag

Mikrotik hostname-script

Mar 28th, 2023 (edited)
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.67 KB | None | 0 0
  1. #!rsc by RouterOS
  2. # RouterOS script: createHostfile
  3. # Copyright (c) 2022 Uco Mesdag <uco@mesd.ag>
  4.  
  5. :global fileContent "";
  6. :foreach dnsEntry in=[ /ip/dns/static/find ] do={
  7.  
  8.   :local ip [ /ip/dns/static/get $dnsEntry address ];
  9.   :local hostname [ /ip/dns/static/get $dnsEntry name ];
  10.   :local comment [ /ip/dns/static/get $dnsEntry comment ];
  11.  
  12.  
  13.   # Only get record for static ip addresses (no #DHCP)
  14.   :if ( [ :len $comment ] = 0 ) do={
  15.     :if ( [ :len $hostname ] != 0 ) do={
  16.       :set fileContent ($fileContent . $ip . " " . $hostname . "\r\n");
  17.     };
  18.   };
  19. };
  20.  
  21. :put $fileContent;
  22.  
  23. /file print file=hostsfile;
  24. /file set hostsfile.txt contents="$fileContent";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement