move global-functions-custom-phg.rsc to global-functions.d/phg.rsc to have it automatically loaded by the main global-functions script
This commit is contained in:
parent
9df26ecebe
commit
0b7671f832
2 changed files with 16 additions and 28 deletions
40
global-functions.d/phg.rsc
Normal file
40
global-functions.d/phg.rsc
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#!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
|
||||
:global SafeResolve
|
||||
|
||||
# Function: safelyResolve
|
||||
# - Takes a DNS string (e.g. "example.com")
|
||||
# - Takes an IP type [ipv4, ipv6]
|
||||
# - Returns a string of an IP address or false if it can't be resolved
|
||||
:set SafeResolve do={
|
||||
:do {
|
||||
:local DomainName [ :tostr $1 ];
|
||||
:local IPType;
|
||||
:if ( ([ :tostr $2 ] = "ipv4") or ([ :tostr $2 ] = "ipv6") ) do={
|
||||
:set IPType [ :tostr $2 ];
|
||||
} else={
|
||||
:global ExitError; $ExitError false $0;
|
||||
}
|
||||
:local ResolvedIP [:resolve domain-name="$DomainName" type=$IPType];
|
||||
:return "$ResolvedIP";
|
||||
} on-error={
|
||||
:return false;
|
||||
}
|
||||
}
|
||||
|
||||
# signal we are ready
|
||||
:set GlobalFunctionsCustomPhgReady true;
|
||||
Loading…
Add table
Add a link
Reference in a new issue