Lo script è questo
- Codice: Seleziona tutto
# Define User Variables
:global ddnspass "xx"
:global ddnshost "xx"
#:global ddnspool "pool0"
#:global ddnsinterface "bridge"
#:global ddnsinterface "6to4-henet"
#:global ddnsinterface "pppoe-out1"
#:global ddnsinterface "ether1"
# Define Global Variables
:global ddnsip
:global ddnslastip
:if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" }
# Define Local Variables
:local int
# Loop thru interfaces and look for ones containing
# default gateways without routing-marks
:if ([ :typeof $ddnsinterface ] != "str" ) do={
:foreach int in=[ /ipv6 address find global ] do={
:local testip [ /ipv6 address get $int address ]
:if ($testip in "fe80::/10" || $testip in "fc00::/7") do={
} else={
:global ddnsip $testip
}
}
} else={
:if ([ :typeof $ddnspool ] != "str" ) do={
# Grab the current Global IP address on that interface.
:foreach int in=[ /ipv6 address find interface=$ddnsinterface global ] do={
:local testip [ /ipv6 address get $int address ]
:if ($testip in "fe80::/10" || $testip in "fc00::/7") do={
} else={
:global ddnsip $testip
}
}
} else={
# Grab the current Global IP address on that interface from spec ip pool.
:global ddnsip [ /ipv6 address get [ /ipv6 address find interface=$ddnsinterface from-pool=$ddnspool ] address ]
}
}
# Did we get an IP address to compare?
:if ([ :typeof $ddnsip ] = nil ) do={
:log info ("DynDNS: No ip address present on please check.")
} else={
:log info ("DynDNS: check IPv6 UPDATE " . $ddnsip)
:if ($ddnsip != $ddnslastip) do={
:log info "DynDNS: Sending IPv6 UPDATE!"
:local str "api/update\?hostname=$ddnshost&ipv6=$ddnsip&token=$ddnspass"
/tool fetch address="dynv6.com" host="dynv6.com" src-path="$str" mode=https dst-path=("/dynv6.".$ddnshost)
:delay 1
:local str [/file find name="dynv6.$ddnshost"];
/file remove $str
:global ddnslastip $ddnsip
}
}
# legacy IPv4
# Define Global Variables
:global ddnsip4
:global ddnslastip4
:global ddnsinterface4
:if ([ :typeof $ddnslastip4 ] = nil ) do={ :global ddnslastip4 "0" }
# Loop thru interfaces and look for ones containing
# default gateways without routing-marks
:local intfinder ""
:foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes ] do={
:set $intfinder [:tostr [/ip route get $int gateway-status]]
:set $intfinder [:pick $intfinder ([:find $intfinder "via"]+5) [:len $intfinder]]
:set $ddnsinterface4 $intfinder
}
# Grab the current IP address on that interface.
:set ddnsip4 [ /ip address get [/ip address find interface=$ddnsinterface4 ] address ]
:set ddnsip4 [:pick $ddnsip4 0 [:find $ddnsip4 "/"] ]
# Did we get an IP address to compare?
:if ([ :typeof $ddnsip4 ] = nil ) do={
:log info ("DynDNS: No ip address present on " . $ddnsinterface4 . ", please check.")
} else={
:log info ("DynDNS: check IPv4 UPDATE " . $ddnsip4)
:if ($ddnsip4 != $ddnslastip4) do={
:log info "DynDNS: Sending IPv4 UPDATE!"
:local str "api/update\?hostname=$ddnshost&ipv4=$ddnsip4&token=$ddnspass"
/tool fetch address="dynv6.com" host="dynv6.com" src-path="$str" mode=https dst-path=("/dynv6.".$ddnshost)
:delay 1
:local str [/file find name="DynDNS.$ddnshost"];
/file remove $str
:global ddnslastip4 $ddnsip4
}
}
Grazie