Script to find IPv6 address dynamically assigned to known MAC address on LAN?

RB5009 with ROS 7.16.2 (stable) and firmware 7.16.2
Setup done with Winbox 64bit v3.41 on Windows 10 Pro.
This is my home setup.

I put some of my hosts on my LAN in the IP DNS Static list and that’s easy since I put those hosts on static IPv4 addresses first. How can I do the same for dynamically assigned IPv6?

This is a one line hack to use /ipv6 neighbor, but it would need to run periodically to have any effect. I’m just picking the “fe80” since this is just for my LAN and it works for my use. This updates the static dns record number 1.

/ipv6 neighbor; :foreach i in=[find where mac-address="AA:BB:CC:DD:EE:FF"] do={:local i2 [get $i]; :toarray $i2; :local i3 [:pick $i2 1]; :if ($i3 ~"^fe80") do={:ip dns static set numbers=1 address=$i3}}

I know that DHCPv6 has the “na-address” variable, but I don’t know how to use it. If I put this in the DHCPv6 script section the global variable is not created nor set. And it’s only executed once when I press the “Apply” button.

:if ([:len $"na-valid"] != 0 ) do={:global navalid $"na-valid"}

And if I change it to log instead the log contains wrongly encoded data. The same for the “na-valid” and “options” variables too.

:if ([:len $"na-address"] != 0 ) do={:log info message=$"na-address"}

How can I change the encoding so I receive the data in a usable/readable encoding?

Is the na-address variable the one I’m looking for at all? If so, how to use it? If not, how can this be done?

If you read changelogs, help and forum, you learn that actually, on actual stable version, netwatch dhcp, ppp, etc.
sciripts are runned on different user that can’t interac with global variables, and other restricted permissions.



Second rule:
Never use numbers and similar on script.
(The first is never use variables name like parameters name, not this case.)
The correct form is something like […]do={**/**ip dns static set [:find where <>] address=$i3}[…]


What is it for? It’s like writing uselessly anywhere in the script (1+1).
Is useless, $i2 is already one array, but the correct form, if of any utility is […]; :set i2 [:toarray $i2**]**;[…]



All this just for […]:foreach i in=[find where mac-address=“AA:BB:CC:DD:EE:FF” and address~“^fe80”] do={ […] } ?
(however, not the correct way)



You obtain a single IPv6 to DHCP client, or a prefix???
:log info “pd-prefix $“pd-prefix””



The forum is full of correct examples.

Thanks for the reply and corrections! Appreciated.

I must admit I find the information hard to find, but I’ll do a better job with my research.

  1. The fact that scripts are run on different user, why isn’t this mentioned in the first place in the docs? After all, this is where all first time users are pointed to by Mikrotik.
    https://help.mikrotik.com/docs/spaces/ROS/pages/47579229/Scripting

Toarray was used on $i because I wasn’t able to get the correct data out of $i unless I changed it. But what do I know, usererrror on my part clearly since :set is correct.

Sorry for my script to be verbose and not perfect. Often it’s better to be verbose at first and then compact things. Nice to know that it’s still not correct.

I obtain both a single IPv6, a prefix and DNS from my ISP via DHCPv6-client. Note, this is a home setup. Note the change in the second hextet for all three types.
Single IP 2a04:980:xxxx:xxxx::1/128
Prefix 2a04:981:xxxx:dd00::/56
Two DNS IPv6 2a04:983:dc::1 and 2a04:983:dc::2

All my clients on the LAN uses IPv6 adddresses from that prefix (DHCP-PD from the RB5009).

Somehow I think you missed my point. Everything with IPv6 is working. I’m not looking for the $na-address between my ISP and myself but from the RB5009 and my LAN clients. If that’s even the one I’m looking for.

I was just looking for a way to dynamically find either the working IPv6 or the FE80:: address for (several) known MAC addresses on my LAN to add to the static DNS. I probably shouldn’t have posted any script as that clearly took away the point of my post. Using /ipv6 neighbor is probably the wrong way too.

And $pd-valid and $pd-prefix is not the problem. But $na-valid and $na-address returns data wrongly encoded (garbage characters).

I’ll search for how to run scripts the correct way and if there’s a correct way to obtain the needed information.

Thanks.

This is the log entry from the $na-valid, $na-address and $options variables mentioned here: https://help.mikrotik.com/docs/spaces/ROS/pages/24805500/DHCP#DHCP-Properties.1

log.JPG

Nextgentel use 2a04:980::/29 that go from 2a04:980::/29 to 2a04:987:…/29 so is coherent.

If you log the array, winbox or webfig can’t show correct hex values.

Try to use this for log:

:log info "na-prefix $[:convert $"na-prefix" from=raw to=hex]"

WARNING: Do not publish result of anything o forum, if you do not know what is it.
This can expose your public IPv6, so is better to contact directly mikrotik support if you obtain garbage (except for $option that is correct)


Jeg kan ikke gjøre noe annet, jeg ønsker deg en god dag.

What's the correct way to keep this running in the background so that it gets triggered when a new LAN host connects?

Thank you, happy new year.