colinardo
Goto Top

Mikrotik Scripting: Resolve Domain to IPv6 Address

Hello Mikrotik users.

Unfortunately Mikrotik does not provide an explicit function for resolving DNS names to IPv6 addresses. The :resolve function only returns a single IPv4 address when both v4 and v6 addresses exist for this domain, which you can see with this terminal command
But if you need to get the IPv6 counterpart you can do this with a trick by using a temporary IPv6 firewall address list.
You could have used web services and external APIs and make an http call using /tool fetch on the device, but I wanted solve this without using external services.

As a result, I wrote an easy to use global function for the problem:


back-to-topFunction "$resolveipv6"


The function, once called in a script, can be used like this in scripts or on the console:

back-to-topOutput of addresses on the console (returns an array if there are multiple addresses)

Results in an array of two addresses

back-to-topStore result in a variable and retrieve individual addresses via index


Important note: If you put the function in a startup script it will be available in all scripts and the console as soon as you declare it once by this call:
Maybe this is helpful for someone until Mikrotik itself provides an IPv6 capable resolve variant.

Greetings and all the best for the new year.
@colinardo

Content-Key: 5151910821

Url: https://administrator.de/contentid/5151910821

Printed on: February 2, 2023 at 00:02 o'clock