Community discussions

 
Savanture
just joined
Topic Author
Posts: 4
Joined: Wed Aug 07, 2019 12:02 am
Location: Moscow, Russian Federation

DDNS update script for nic.ru (rucenter)

Wed Aug 07, 2019 12:31 am

Hi, Mikrotik community.
Just want to share here my script for updating DDNS record hosted on nic.ru. Maybe someone will need it:
Following variables should be filled:
1. interface - interface name
2. domain - your domain name
3. username and password - you will receive them in special site tab for DDNS. It's NOT a login and password to a site.
4. debugflag - if set to true script will post a message to log every launch. When false - only errors are posted to log.
Works on RouterOS 6.45.3.

Code: Select all

#Golbal address variable
:global whiteip

#Degug flag to save log :)
:local debugflag false

#Interface name
:local interface "my_interface_name"

#Address of NIC DDNS update interface
:local address "api.nic.ru/dyndns/update\?hostname="

#My account data
:local domain "myhost.com"
:local username "my_username"
:local password "my_password"

#String with interface status
:local interfacestatus [/interface l2tp-client monitor [/interface l2tp-client find name=$interface] once as-value]

#Check my IP address has been changed
:if ($interfacestatus->"local-address" != $whiteip) do={

#Check that interface in connected state
:if ($interfacestatus->"status" = "connected") do={

#Send request to update IP to NIC
:local response [/tool fetch mode=https url="https://$username:$password@$address$domain" as-value output=user]
#Use string below for testing purposes (comment the upper)
#:local response {data="good 1.2.3.4";downloaded=0;duration="00:00:03";status="finished";total=0}

:local result ($response->"data")
:local checkresult [:pick $result 0 4]

:if ( $checkresult = "good") do={
:set whiteip ($interfacestatus->"local-address")
:if ( $debugflag ) do={
:log info "DDNS update successfull: $result"
}
} else={
:set whiteip 0.0.0.0
:log error "DDNS update failed: $result"
}

} else={
:set whiteip 0.0.0.0
:log error "DDNS: Interface is down or not found"
}
} else={
:if ( $debugflag ) do={
:log info "DDNS: no update needed. IP not changed"
}
}

Who is online

Users browsing this forum: No registered users and 11 guests