Initial commit
This commit is contained in:
parent
e805f765e7
commit
eb1fa8d1c6
38
IPv6HelperFunctions.rsc
Normal file
38
IPv6HelperFunctions.rsc
Normal file
|
@ -0,0 +1,38 @@
|
|||
# -------------------------------------------------------------------------------
|
||||
# IPv6 helper functions
|
||||
#
|
||||
# by Philip 'ShokiNN' Henning <mail@philip-henning.com>
|
||||
# RouterOS compatibility: 7+
|
||||
# Version 1.0
|
||||
# last update: 20.01.2025
|
||||
# License: MIT
|
||||
# -------------------------------------------------------------------------------
|
||||
|
||||
# ---------------------------
|
||||
# Function: resolveIPv6
|
||||
# - Takes an DNS string (e.g. "example.com")
|
||||
# - Returns a string of and IPv6 address
|
||||
# ---------------------------
|
||||
:global resolveIPv6 do={
|
||||
:local result [:toarray ""]
|
||||
:local maxwait 5
|
||||
:local cnt 0
|
||||
:local listname "tmp-resolve$cnt"
|
||||
/ipv6/firewall/address-list {
|
||||
:do {
|
||||
:while ([:len [find list=$listname]] > 0) do={
|
||||
:set cnt ($cnt + 1)
|
||||
:set listname "tmp-resolve$cnt"
|
||||
}
|
||||
:set cnt 0
|
||||
add list=$listname address=$1
|
||||
:while ([find list=$listname && dynamic] = "" && $cnt < $maxwait) do={:delay 1;:set cnt ($cnt +1)}
|
||||
:foreach i in=[find list=$listname && dynamic] do={
|
||||
:local rawip [get $i address]
|
||||
:set result ($result, [:pick $rawip 0 [:find $rawip "/"]])
|
||||
}
|
||||
remove [find list=$listname && !dynamic]
|
||||
}
|
||||
}
|
||||
:return $result
|
||||
}
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2025 phg
|
||||
Copyright (c) 2025 Philip Henning
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
|
80
dnsToIPv6SubnetResolver.rsc
Normal file
80
dnsToIPv6SubnetResolver.rsc
Normal file
|
@ -0,0 +1,80 @@
|
|||
# -------------------------------------------------------------------------------
|
||||
# Script to grab IPv6 Addresses from DNS an converting them to subnets
|
||||
#
|
||||
# by Philip 'ShokiNN' Henning <mail@philip-henning.com>
|
||||
# RouterOS compatibility: 7+
|
||||
# Version 1.0
|
||||
# last update: 20.01.2025
|
||||
# License: MIT
|
||||
# -------------------------------------------------------------------------------
|
||||
|
||||
# --- Define variables -----------------------------------------------------------------------------------------
|
||||
# Enter all required variables and secrets here. -- All secrets are stored unencrypted!
|
||||
## IPv6 address list (address list which will contain the resolved subnets)
|
||||
## Data Type: String
|
||||
## Example: "resolved_ipv6_subnets"
|
||||
:local ipv6AddressList "";
|
||||
|
||||
## --- Comment prefix --------------------------------------------------------------------
|
||||
# Comment Prefix
|
||||
# If set, prefixes the comment for the address list
|
||||
# Data Type: String
|
||||
# Example: Access to service for
|
||||
## ---------------------------------------------------------------------------------------
|
||||
:local ipv6AddressListCommentPrefix "";
|
||||
|
||||
## --- Public domains to resolve --------------------------------------------------------------------
|
||||
# Domain
|
||||
# The Domain you want to resolve into an IPv6 subnet
|
||||
# Data Type: String
|
||||
# Example: "example.com";
|
||||
|
||||
# Subnet length
|
||||
# The subnet length the resolved IP address should be reduced to
|
||||
# Data Tupe: Integer
|
||||
# Example: 64;
|
||||
|
||||
# Comment
|
||||
# Comment for the Address list entry
|
||||
# Data Type: String
|
||||
# Example: "John Doe's public subnet";
|
||||
## --------------------------------------------------------------------------------------------------
|
||||
:local domainToIpv6Subnet {
|
||||
{"example.com";64;"John Doe"}
|
||||
};
|
||||
# ---------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
:local logPrefix "[DNS to IPv6 Subnet resolver]";
|
||||
|
||||
|
||||
# Log "run of script"
|
||||
:log info "$logPrefix running";
|
||||
|
||||
:local index 0;
|
||||
:foreach i in=$domainToIpv6Subnet do={
|
||||
[/system/script/run "ipv6HelperFunctions"; global resolveIPv6];
|
||||
|
||||
:local configDomain ("$($i->0)");
|
||||
:local configSubnetLength ("$($i->1)");
|
||||
:local configComment ("$ipv6AddressListCommentPrefix" . "$($i->2)");
|
||||
:local dnsIp "";
|
||||
:local startLogMsg "$logPrefix Start configuring domain:";
|
||||
:local endLogMsg "$logPrefix Finished configuring domain:";
|
||||
|
||||
:log info "$startLogMsg $configDomain";
|
||||
/ipv6/firewall/address-list/remove [/ipv6/firewall/address-list/find list="$ipv6AddressList" comment="$configComment"];
|
||||
|
||||
:set dnsIp [$resolveIPv6 $configDomain];
|
||||
:if ($dnsIp != "") do={
|
||||
/ipv6/firewall/address-list/add list="$ipv6AddressList" address="$dnsIp/$configSubnetLength" comment="$configComment";
|
||||
:local addedSubnet [:pick [/ipv6/firewall/address-list/get [/ipv6/firewall/address-list/find list="$ipv6AddressList" comment="$configComment"]] 1];
|
||||
}
|
||||
|
||||
:log info "$logPrefix domain: $configDomain - Set to: $addedSubnet";
|
||||
|
||||
:log info "$endLogMsg $configDomain";
|
||||
};
|
||||
:set index;
|
||||
|
||||
:log info "$logPrefix finished";
|
Loading…
Reference in a new issue