2025-01-27 20:27:59 +00:00
|
|
|
#!rsc by RouterOS
|
|
|
|
# RouterOS script: global-functions-custom-phg
|
|
|
|
# Copyright (c) 2025 Philip 'ShokiNN' Henning <mail@philip-henning.com>
|
|
|
|
# https://git.s1q.dev/phg/routeros-scripts-custom/about/COPYING.md
|
|
|
|
#
|
|
|
|
# requires RouterOS, version=7.14
|
|
|
|
#
|
|
|
|
# global functions for my custom scripts
|
|
|
|
# https://git.s1q.dev/phg/routeros-scripts-custom/about
|
|
|
|
|
|
|
|
:local ScriptName [ :jobname ];
|
|
|
|
|
|
|
|
# global variables not to be changed by user
|
|
|
|
:global GlobalFunctionsCustomPhgReady false;
|
|
|
|
|
|
|
|
# global functions
|
2025-01-27 21:28:54 +00:00
|
|
|
:global SafeResolve
|
2025-01-27 20:27:59 +00:00
|
|
|
|
|
|
|
# Function: safelyResolve
|
|
|
|
# - Takes a DNS string (e.g. "example.com")
|
|
|
|
# - Takes an IP type [ipv4, ipv6]
|
|
|
|
# - Returns a string of and IP address or false if it can't be resolved
|
2025-01-27 21:28:54 +00:00
|
|
|
:set SafeResolve do={
|
2025-01-27 20:27:59 +00:00
|
|
|
:do {
|
|
|
|
:local DomainName [ :tostr $1 ];
|
2025-01-27 21:28:54 +00:00
|
|
|
:local IPType;
|
|
|
|
:if ( ([ :tostr $2 ] = "ipv4") or ([ :tostr $2 ] = "ipv6") ) do={
|
|
|
|
:set IPType [ :tostr $2 ];
|
2025-01-27 20:27:59 +00:00
|
|
|
} else={
|
2025-01-27 21:28:54 +00:00
|
|
|
:global ExitError; $ExitError false $0;
|
2025-01-27 20:27:59 +00:00
|
|
|
}
|
2025-01-27 21:28:54 +00:00
|
|
|
:local ResolvedIP [:resolve domain-name="$DomainName" type=$IPType];
|
|
|
|
:return "$ResolvedIP";
|
2025-01-27 20:27:59 +00:00
|
|
|
} on-error={
|
2025-01-27 21:28:54 +00:00
|
|
|
:return false;
|
2025-01-27 20:27:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# signal we are ready
|
2025-01-27 21:28:54 +00:00
|
|
|
:set GlobalFunctionsCustomPhgReady true;
|