I added auto adding of route to ChangeIP.com update server.
This is need in case when you have two ISP, one with static IP and second with dynamic IP.
Code: Select all
# Set your specific ChangeIP.com preferences here.
:global ddnsuser "YourChangeIPUserID"
:global ddnspass "PASSWORD"
:global ddnshost "MyRouterHostname.example.org"
:global ddnsinterface "ether2"
# Get ChangeIP.com server IP address.
:global ddnsserver [:resolve "nic.changeip.com"];
:global ddnsfip [:resolve "ip.changeip.com"]
# Change ddnsport to 8245 to bypass proxy.
:local ddnsport 80
# Do not edit anything below this line. You have been warned.
# Abusive updates to the system will cause firewall blocks.
# Please be considerate and
# do not let this script run more than once per 3-5 minutes.
:log info "DDNS: Starting."
# Initialize checkpoint
:global ddnscheckpoint
:if ([:typeof $ddnscheckpoint] = "time") do={
:log info ("DDNS: Last check was " . ([/system clock get time] - $ddnscheckpoint))
} else={
:log info "DDNS: Cannot determine checkpoint, set now."
:global ddnscheckpoint ( [/system clock get time] - 1d )
}
# Set route for ChangeIP.com server
:if ([:len [/ip route find comment="DDNS Server"]] > 0) do={
:if ([/ip route get [find comment="DDNS Server"] dst-address] != [$ddnsserver . "/32"]) do={
/ip route set [find comment="DDNS Server"] dst-address=$ddnsserver
:log info "DDNS: Route to server was updated."
}
} else={
/ip route add dst-address=$ddnsserver gateway=$ddnsinterface comment="DDNS Server"
:log info "DDNS: Route to server was added."
}
# Set route for ChangeIP.com IP finder
:if ([:len [/ip route find comment="DDNS IP"]] > 0) do={
:if ([/ip route get [find comment="DDNS IP"] dst-address] != [$ddnsfip . "/32"]) do={
/ip route set [find comment="DDNS IP"] dst-address=$ddnsfip
:log info "DDNS: Route to IP was updated."
}
} else={
/ip route add dst-address=$ddnsfip gateway=$ddnsinterface comment="DDNS IP"
:log info "DDNS: Route to IP was added."
}
# Get the current IP
:if ([/system clock get time] - $ddnscheckpoint > [:totime 180s] || [/system clock get time] - $ddnscheckpoint < [:totime 0s]) do={
:log info "DDNS: Performing remote IP detection."
/tool fetch address="ip.changeip.com" host="ip.changeip.com" src-path=("/?" . [/int eth get [find name=$ddnsinterface] mac-address ]) dst-path="ip.changeip.com.txt" mode=http port=$ddnsport
:global ddnscheckpoint [/system clock get time]
} else={
:log info "DDNS: Please be considerate and wait a few seconds longer."
:break
}
# Parse the IP address received from fetch script.
:global ddnslastip
:local html [/file get "ip.changeip.com.txt" contents]
:local ddnsip [:pick $html ([:find $html "<!--IPADDR="] + 11) [:find $html "-->"] ]
# Is it a valid IP and is it different than the last one?
:if ([:typeof [:toip $ddnsip]] = "ip" AND $ddnsip != $ddnslastip ) do={
:log info "DDNS: Sending UPDATE with $ddnsip"
:log info [/tool dns-update name=$ddnshost address=$ddnsip key-name=$ddnsuser key=$ddnspass ]
:global ddnslastip $ddnsip
} else={
:log info "DDNS: No update required."
}
}
Regards,
Mladen