Created
April 20, 2024 02:17
-
-
Save elico/094ad493fa5a3555e12cc9a34e077692 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
:do { | |
:local debug 1; | |
:local flagInterface ""; | |
:local srcInterface ""; | |
:local srcAddress ""; | |
:set srcInterface "###INTERFACE_NAME###"; | |
:set flagInterface "###FLAG_INTERFACE_NAME###"; | |
if ( $debug > 0 ) do={ | |
:log info "Debug step1"; | |
} | |
:local ipAddressesForInterface [:len [/ip/address/find where interface=$srcInterface and disabled=no ]]; | |
if ( $debug > 0 ) do={ | |
:log info "Debug step2"; | |
if ( $ipAddressesForInterface > 1 ) do={ | |
:log info "ERR, there are more then 1 ip addresses for the interface"; | |
} | |
} | |
:local srcAddressCidr [/ip/address/get [find where interface=$srcInterface and disabled=no] address ]; | |
:local urlString "###URL###"; | |
:local result ""; | |
:log info "Debug step3"; | |
:do { | |
if ([/interface/bridge/print count-only where name=$flagInterface ] = 0) do={ | |
[/interface/bridge/add name=$flagInterface disabled=yes]; | |
} | |
} on-error={ | |
:log info "Error creating the flag interface"; | |
} | |
:local currentFlagDisabledState [/interface/bridge/get [find where name=$flagInterface ] value-name=disabled ]; | |
:for i from=( [:len $srcAddressCidr] - 1) to=0 do={ | |
:if ( [:pick $srcAddressCidr $i] = "/") do={ | |
:set srcAddress [:pick $srcAddressCidr 0 $i]; | |
} | |
} | |
:do { | |
:set result [/tool/fetch src-address=$srcAddress url=$urlString as-value output=none]; | |
if ($currentFlagDisabledState = true) do={ | |
[/interface/bridge/set [find where name=$flagInterface ] disabled=no ]; | |
} | |
} on-error={ | |
:log info ("Error downloading url: " . $urlString); | |
if ($currentFlagDisabledState = false) do={ | |
[/interface/bridge/set [find where name=$flagInterface ] disabled=yes]; | |
} | |
} | |
:log info "success"; | |
} on-error={ | |
:log info "Runtime Error"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment