Created
December 9, 2015 08:02
-
-
Save luginbash/f9622e6cc15b5055096e to your computer and use it in GitHub Desktop.
Add interface IPv4 address to a global var
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
# Change to the name of interface that gets the dynamic IP address | |
:local inetinterface "pppoe-out1"; | |
# use search & replace all on myEndpoint for multiple hosts | |
:global myEndpoint; | |
:if ([/interface get $inetinterface value-name=running]) do={ | |
# Get the current IP on the interface | |
:local currentIP [/ip address get [find interface="$inetinterface" disabled=no] address]; | |
# Strip the net mask off the IP address | |
:for i from=( [:len $currentIP] - 1) to=0 do={ | |
:if ( [:pick $currentIP $i] = "/") do={ | |
:set currentIP [:pick $currentIP 0 $i]; | |
} | |
} | |
:if ($currentIP != $myEndpoint) do={ | |
:set myEndpoint $currentIP; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment