Community discussions

MikroTik App
 
User avatar
boldsuck
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 60
Joined: Sun Sep 01, 2013 1:07 am
Location: Germany

DynDNS Update Script for EasyDNS, that cares about TOS and return status.

Tue Jun 13, 2017 6:56 pm

Hello,
because Oracle bought DynDNS I'm changed to easyDNS. :D

Perhaps someone can use the update script. I found none for easyDNS in the MicroTik-wiki.
Tested and runs here on RB2011UAS (mips), RB450Gx4 (arm), wAP R ac (arm), mAP lite (mips) with RouterOS v6.n & v7.n

Thanks to -Greg (gslop) for his script. 8) I've only adjusted something.
viewtopic.php?f=2&t=60018

Script name=easyDNS, owner=admin, policy=ftp,read,write,policy,test
# Copyright by: Gregory Sloop under the GPL3, (see: http://www.gnu.org/licenses/gpl.html)
# Written by:   Gregory Sloop <gregs@sloop.net> last modified,  Mar 25 2012 , v1.0.5
# Modified by:  Marco Maske <root@boldsuck.de>  last modified,  Nov 25 2016 , v1.1.0e
#
#  DynDNS (acquired by Oracle) update script, changed for EasyDNS.
#  shameless taken from https://forum.mikrotik.com/viewtopic.php?f=2&t=60018

########################
# Set needed variables #
########################
# EasyDNS account username, dynamic token & hostname.
# NOTE: Dynamic tokens must be entered in place of your account password, as many updaters only use clear text.
# EasyDNS only allow the use of the token to avoid exposing your password.
:local username "your-username"
:local dyntoken "your-dyntoken"
:local hostname "your.domain.net"

# Which interface are we checking?
:local Interface "pppoe-out1"

# The file name where the last recorded IP will be stored,
# as well as the file name of the easyDNS response.
:local vLastIPFileName "easydns-lastip.txt"
:local vEasyDNSResponseFile "easydns-resp.txt"

############################
# END Set needed variables #
############################

:local vRawIP
:local vJustIP
:local currentIP
:local previousIP
:local vlocalurl
:local vIPChanged false
:local easyDNSresult
:local result

# Check for file existance,
# if not create it...
# We need to do this before we try to read or write to files.
:local check [/file find name=$vLastIPFileName]
:if ( $check = "" ) do= {
        /file print file=$vLastIPFileName
        :delay 2
        /file set [/file find name=$vLastIPFileName] contents=""
}

# Get the last saved IP from the file.
:set previousIP [/file get $vLastIPFileName contents]


# Print some debug info
#:log info ("easyDNS: Username = $username")
#:log info ("easyDNS: Dynamictoken = $dyntoken")
#:log info ("easyDNS: Hostname = $hostname")
#:log info ("easyDNS: Interface = $Interface")
#:log info ("easyDNS: PreviousIP = $previousIP")


# This code gets the current IP from the interface.
# The interface we're checking should be set above.
# Get the raw IP from the interface, which includes a mask.
:set vRawIP [:tostr [/ip address get [find interface=$Interface] address]]

# Strip the netmask off the vRawIP address.
:for i from=( [:len $vRawIP] - 1) to=0 do={
	:if ( [:pick $vRawIP $i] = "/") do={
		:set vJustIP [:pick $vRawIP 0 $i]
	}
}
:set currentIP $vJustIP

# Determine if easyDNS update is needed.
# More easyDNS updater request details:
# https://cp.easydns.com/support/dynamic/ or https://kb.easydns.com/knowledge/dynamic-dns/
#
# Update if the currentIP isn't equal to previousIP.
:if (($currentIP != $previousIP)) do={
	:log info ("easyDNS: Hostname = $hostname")
	:log info ("easyDNS: CurrentIP = $currentIP ==> PreviousIP = $previousIP")
	:set vlocalurl ("https://" . "$username" . ":" . "$dyntoken" . "@" . "api.cp.easydns.com" . "/dyn/tomato.php?hostname=" . "$hostname" . "&myip=" . "$currentIP")
#
# https://username:dyntoken@api.cp.easydns.com/dyn/tomato.php?hostname=example.com&myip=10.0.0.2 => txt response
# dynsite.php, ez-ipupdate.php, tomato.php => All have the same 3-line txt response.
# https://username:dyntoken@api.cp.easydns.com/dyn/generic.php?hostname=example.com&myip=10.0.0.2 => html response
#
	/tool fetch mode=https url=$vlocalurl dst-path=$vEasyDNSResponseFile
	:set result [/file get $vEasyDNSResponseFile contents]
	:set vIPChanged true
} else={
	:log info ("easyDNS: No update needed.")
}

# Get the result status code and pull it out for use.
# If IPChanged = true
#	Get result code
#		Check easyDNS result
#		if NOERROR or OK then
#			:set previousIP $currentIP
#			/file set [/file find name=$vLastIPFileName] contents="$currentIP"
#			also post the result to the log file
#		else NOACCESS, NOSERVICE, ILLEGAL INPUT, TOO_FREQ or TOOSOON
#			post to log file
#			Don't update previousIP or vLastIPFileName file
:if ($vIPChanged=true) do={
	:set result [/file get $vEasyDNSResponseFile contents]
	:local endLoc [:find $result "\n" -1]
	:set easyDNSresult [:pick $result -1 ($endLoc)]
	:put $easyDNSresult
		:if ( ($easyDNSresult = "NOERROR") || ($easyDNSresult = "OK") ) do={
			:set previousIP $currentIP
			:log info ("easyDNS: Update IP needed...")
			:log info ("easyDNS: Update result: ".$result)
			/file set [/file find name=$vLastIPFileName] contents="$currentIP"
		} else={
			:log info ("easyDNS: Update IP needed...")
			:log info ("easyDNS: Update FAILED")
			:log info ("easyDNS: Update result: ".$result)
		}
}

/system scheduler
add interval=15m name=easyDNS on-event="system script run easyDNS" policy=ftp,read,write,policy,test start-time=startup
Last edited by boldsuck on Sat Sep 03, 2022 6:57 pm, edited 1 time in total.
 
User avatar
boldsuck
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 60
Joined: Sun Sep 01, 2013 1:07 am
Location: Germany

Re: DynDNS Update Script for EasyDNS, that cares about TOS and return status.

Sat Sep 03, 2022 6:19 pm

I also have the script for dyn IPv6 updates.

Script name=easyDNSv6, owner=admin, policy=ftp,read,write,policy,test
# Copyright by: Gregory Sloop under the GPL3, (see: http://www.gnu.org/licenses/gpl.html)
# Written by:   Gregory Sloop <gregs@sloop.net> last modified,  Mar 25 2012 , v1.0.5
# Modified by:  Marco Maske <root@boldsuck.de>  last modified,  Jan 01 2022 , v1.1.1e

# EasyDNS dynamic-dns IPv6 update script

########################
# Set needed variables #
########################
# EasyDNS account username, dynamic token & hostname.
# NOTE: Dynamic tokens must be entered in place of your account password, as many updaters only use clear text.
# EasyDNS only allow the use of the token to avoid exposing your password.
:local username "your-username"
:local dyntoken "your-dyntoken"
:local hostname "your.domain.net"

# Which interface are we checking?
:local Interface "bridge-local"

# The file name where the last recorded IPv6 will be stored,
# as well as the file name of the easyDNS response.
:local vLastIPv6FileName "easydns-lastipv6.txt"
:local vEasyDNSv6ResponseFile "easydns-v6resp.txt"

############################
# END Set needed variables #
############################

:local currentIPv6
:local previousIPv6
:local vlocalurl
:local vIPv6Changed false
:local easyDNSv6result
:local result

# Check for file existance,
# if not create it...
# We need to do this before we try to read or write to files.
:local check [/file find name=$vLastIPv6FileName]
:if ( $check = "" ) do= {
        /file print file=$vLastIPv6FileName
        :delay 2
        /file set [/file find name=$vLastIPv6FileName] contents=""
}

# Get the last saved IPv6 from the file.
:set previousIPv6 [/file get $vLastIPv6FileName contents]


# Print some debug info.
#:log info ("easyDNS: Username = $username")
#:log info ("easyDNS: Dynamictoken = $dyntoken")
#:log info ("easyDNS: Hostname = $hostname")
:log info ("easyDNS: Interface = $Interface")
:log info ("easyDNS: PreviousIPv6 = $previousIPv6")


# This code gets the current IPv6 from the interface.
# The interface we're checking should be set above.
#############################
# Test in console:
# :put [/ipv6 address get [find interface=bridge-local !link-local] address]
#############################
# Get the IPv6 from the interface, which includes a prefix.
:set currentIPv6 [/ipv6 address get [find interface=$Interface !link-local] address]
# Remove prefix from IPv6 address.
:set currentIPv6 [:pick [:tostr $currentIPv6 ] 0 [:find [:tostr $currentIPv6 ] "/"]]
:log info $currentIPv6


# Determine if easyDNS update is needed.
# More easyDNS updater request details:
# https://cp.easydns.com/support/dynamic/ and https://kb.easydns.com/knowledge/dynamic-dns/
#
# Update if the currentIPv6 isn't equal to previousIPv6.
:if (($currentIPv6 != $previousIPv6)) do={
	:log info ("easyDNS: Hostname = $hostname")
	:log info ("easyDNS: CurrentIPv6 = $currentIPv6 ==> PreviousIPv6 = $previousIPv6")
	:set vlocalurl ("https://" . "$username" . ":" . "$dyntoken" . "@" . "api.cp.easydns.com" . "/dyn/tomato.php?hostname=" . "$hostname" . "&myip=" . "$currentIPv6")
#
# https://username:dyntoken@api.cp.easydns.com/dyn/tomato.php?hostname=example.com&myip=10.0.0.2 => txt response
# dynsite.php, ez-ipupdate.php, tomato.php => All have the same 3-line txt response.
# https://username:dyntoken@api.cp.easydns.com/dyn/generic.php?hostname=example.com&myip=10.0.0.2 => html response
#
	/tool fetch mode=https url=$vlocalurl dst-path=$vEasyDNSv6ResponseFile
	:set result [/file get $vEasyDNSv6ResponseFile contents]
	:set vIPv6Changed true
} else={
	:log info ("easyDNS: No update needed.")
}

# Get the result status code and pull it out for use.
# If IPv6Changed = true
#	Get result code
#		Check easyDNS result
#		if NOERROR or OK then
#			:set previousIPv6 $currentIPv6
#			/file set [/file find name=$vLastIPv6FileName] contents="$currentIPv6"
#			also post the result to the log file
#		else NOACCESS, NOSERVICE, ILLEGAL INPUT, TOO_FREQ or TOOSOON
#			post to log file
#			Don't update previousIPv6 or vLastIPv6FileName file.
:if ($vIPv6Changed=true) do={
	:set result [/file get $vEasyDNSv6ResponseFile contents]
	:local endLoc [:find $result "\n" -1]
	:set easyDNSv6result [:pick $result -1 ($endLoc)]
	:put $easyDNSv6result
		:if ( ($easyDNSv6result = "NOERROR") || ($easyDNSv6result = "OK") ) do={
			:set previousIPv6 $currentIPv6
			:log info ("easyDNS: Update IPv6 needed...")
			:log info ("easyDNS: Update result: ".$result)
			/file set [/file find name=$vLastIPv6FileName] contents="$currentIPv6"
		} else={
			:log info ("easyDNS: Update IPv6 needed...")
			:log info ("easyDNS: Update FAILED")
			:log info ("easyDNS: Update result: ".$result)
		}
}

/system scheduler
add interval=29m name=easyDNSv6 on-event="system script run easyDNSv6" policy=ftp,read,write,policy,test start-time=startup
 
User avatar
diamuxin
Member
Member
Posts: 317
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: DynDNS Update Script for EasyDNS, that cares about TOS and return status.

Sat Sep 03, 2022 8:30 pm

Thanks, it's very helpful.

BR

Who is online

Users browsing this forum: No registered users and 19 guests