Page 1 of 1

IPv6 auto address lists

Posted: Sat Sep 17, 2016 5:50 am
by BrasDeutscher
## IPv6 auto address lists ##
## Written by:BrasDeutscher,PA,Brazil ##
## Testet under RouterOS v6.37rc36 ##
{
## Set your list name here ##
:global list "dynIPv6"

## Set your list time-out here ##
:global tou "12h"

## !!-- DO NOT CHANGE ANY MORE BELOW --!! ##
:global ipv4
:global ipv6
:global mac
:global action
:foreach d in=[/ip dhcp-server lease find where dynamic ] do={
:set mac [/ip dhcp-server lease get $d mac-address ];
:set ipv4 [/ip dhcp-server lease get $d address ];
:if ([/ipv6 neighbor find where mac-address=$mac ] != "" ) do={
:set ipv6 [/ipv6 neighbor get [find where mac-address=$mac ] address ];
:if ([/ipv6 firewall address-list find where dynamic comment="$ipv4 -- $mac" ] = "" ) do={
:set action [/ipv6 firewall address-list add list="$list" address="$ipv6" \
timeout="$tou" comment="$ipv4 -- $mac" ];
:log warning ("IPv6 Fw new $list - Mac: $mac - Address: $ipv4 to $ipv6");
}}}}

Re: IPv6 auto address lists

Posted: Sun Sep 18, 2016 10:13 pm
by 2frogs
Any ideas for running this script for a IP range like 192.168.88.80-192.168.88.89?

Re: IPv6 auto address lists

Posted: Tue Sep 20, 2016 5:17 am
by BrasDeutscher
I'will try this for you, the problem is I do not use this IP Range on my Router ! :?
My Question to you, You use dynamic or static IP leases ???
And why do you need this only for 9 IP addresses ???

Re: IPv6 auto address lists

Posted: Tue Sep 20, 2016 5:58 am
by 2frogs
I do make-static lease, I want to add them to an address list for mangle rules for queues. I have my Business PC in this range, another has Gaming Console, another TV/DVR, etc..

I had already made changes to your original script to put the addresses in one list and I added host-name to the comments and log output! :D

Re: IPv6 auto address lists

Posted: Wed Sep 21, 2016 6:34 am
by 2frogs
@BrasDeutscher I finally figured it out
## IPv6 address lists for subnet range ##
## Adapted from: ##
## IPv6 auto address lists ##
## Orignally Written by:BrasDeutscher,PA,Brazil ##
## Tested under RouterOS v6.37rc30 ##
{
## Set your list name here ##
:local listn "Priority"

## Set your list time-out here ##
:local tou "7d"

:local host
:local ipv4
:local ipv6
:local mac
:local comm

## Set your range in from= and to= ##
:for i from= 80 to= 89 do={

## Set your IP address ##
:set ipv4 "192.168.88.$i";

## !!-- DO NOT CHANGE ANY MORE BELOW --!! ##
:if ([/ip dhcp-server lease find where address=$ipv4 ] != "") do={
:set host [/ip dhcp-server lease get [find where address=$ipv4 ] host-name];
:set mac [/ip dhcp-server lease get [find where address=$ipv4 ] mac-address];
:if ([/ipv6 neighbor find where mac-address=$mac ] != "" ) do={
:set ipv6 [/ipv6 neighbor get [find where mac-address=$mac ] address ];
:if ([/ipv6 firewall address-list find where address=$ipv6 ] != $ipv6 ) do={
:set comm "$host - $ipv4";
/ipv6 firewall address-list add list= $listn address="$ipv6" timeout="$tou" comment= $comm
:log warning ("Add IPv6 Address List for $listn - $comm : $ipv6");
}}}}}
I do appreciate your willingness to help!

Re: IPv6 auto address lists

Posted: Sun Sep 25, 2016 5:31 pm
by BrasDeutscher
Very good!

Re: IPv6 auto address lists

Posted: Fri Jun 26, 2020 4:19 am
by mnowak
thanks, i add some code to the script for my simple queue Qos on target device in my home network.
Create task scheduler that run the script every 15 min.

look:
## IPv6 address lists for subnet range ##
## Adapted from: ##
## IPv6 auto address lists ##
## Orignally Written by:BrasDeutscher,PA,Brazil ##
## Tested under RouterOS v6.37rc30 ##
{
## Set your list name here ##
:local listn "Dispositivos"

## Set your list time-out here ##
:local tou "6h"

:local host
:local ipv4
:local ipv6
:local mac
:local comm

## Set your range in from= and to= ##
:for i from= 10 to= 252 do={

## Set your IP address ##
:set ipv4 "192.168.10.$i";

## !!-- DO NOT CHANGE ANY MORE BELOW --!! ##
:if ([/ip dhcp-server lease find where address=$ipv4 ] != "") do={
:set host [/ip dhcp-server lease get [find where address=$ipv4 ] host-name];
:set mac [/ip dhcp-server lease get [find where address=$ipv4 ] mac-address];
:if ([/ipv6 neighbor find where mac-address=$mac ] != "" ) do={
:set ipv6 [/ipv6 neighbor get [find where mac-address=$mac ] address ];
:if ([/ipv6 firewall address-list find where address=$ipv6 ] != $ipv6 ) do={
:set comm "Agregando $host - $ipv4";
/ipv6 firewall address-list add list= $listn address="$ipv6" timeout="$tou" comment= $comm
:log warning ("Add IPv6 Address List for $listn - $comm : $ipv6");
###
### Added for Mauricio Nowak - update simple queue target with ipv6 addres from prefix isp.
###
:foreach QUEUE in=[/queue simple find target="$ipv4/32"] do={/queue simple set $QUEUE target="$ipv4,$ipv6"};
###
###
}}}}}