freedns.afraid.org Script

Hello

Sorry, I do not know English and therefore I use the translator.

I wrote my own script for freedns.afraid.org

The most important thing!!! The script works if you have multiple domains.




##############	Script FreeDNS.afraid.org	##################
##############	PARSER EDITION	##################
##############	CREATED LESHIY_ODESSA	##################
	
# Specify the "Direct URL", which is https://freedns.afraid.org/dynamic/
# If RouterOS version 5.xx, then remove from the URL encryption - "https" change this to "http". Also see below.
# In front of the sign "?" put a backslash "\".
:global "direct-url" "http://freedns.afraid.org/dynamic/update.php\?dedC0TirYibYdzBYnnhVRiJJb8Q6iDY1Mji3mQ=="

# Specify the URL API "ASCII"
# Log in under your account and open the page https://freedns.afraid.org/api/
# Then copy the URL of your site - Available API Interfaces : ASCII (!!! NOT XML !!!)
# ATTENTION!!!! Before the question mark, put a backslash "\".
# If RouterOS version 5.xx, then remove from the URL encryption - "https" change this to "http".
:global "api-url" "http://freedns.afraid.org/api/\?action=getdyndns&sha=62egb6606ci46cbe6eo8iga61de6ia101858a08n"
 	
# Specify your domain or subdomain.
:global "dns-domain" "name.com"

# Define variables for the external (WAN) interface
# Case sensitive.
:global "out-interface" "pppoe"
 		
# !!!!!!!!!!!!!!!!! Nothing more do not need to edit!!!!!!!!!!!!!!!!!
 		
# Check whether the file with the IP domain - freedns.txt
:if ([:len [/file find name=freedns.txt]] > 0) do={
} else={
/tool fetch url=$"api-url" dst-path="/freedns.txt"
}
# Find out the IP address of the domain using the API and parsing.
# Split the file
:local "result" [/file get freedns.txt contents]
:local "startloc" ([:find $"result" $"dns-domain"] + ([:len $"dns-domain"] + 1))
:local "endloc" ([:find $"result" $"direct-url" -1] -1)
:global "dns-domain-ip" [:pick $"result" $"startloc" $"endloc"]
 		
# Find the current IP address on the external interface
:global "current-ip" [/ip address get [find interface=$"out-interface"] address]
 	
# Obtained from IP addresses to be excluded subnet mask
:set "current-ip" [:pick $"current-ip" 0 ([:len $"current-ip"]-3) ]
 		
# Compare the external IP with the IP address of the DNS domain.
:if ($"current-ip" != $"dns-domain-ip") do={

# If different, then sent to freedns.afraid.org our external IP by using Direct URL
:log info ("Service Dynamic DNS: old IP address $"dns-domain-ip" for $"dns-domain" CHANGED to -> $"current-ip"")
/tool fetch url=$"direct-url" keep-result=no
# Download the file with the new IP after 5 sec.
:delay 5
/tool fetch url=$"api-url" dst-path="/freedns.txt"
} else={
# Not to clog the log, you need to comment out this line.
:log info ("IP address is NOT CHANGED, the update is not required")
}
 	
# Since version RouterOS version 6.0rc12 supported encryption /tool fetch mode=https
# In :global "direct-url" need to change to httpS://
# For RouterOS version 6.xx
# /tool fetch mode=https url=$"direct url"
# :global "direct-url" "https://freedns.afraid.org/dynamic/update.php\?UVdjU2lzQmQwSkdjZW9aWkNleTdJdXFtOjg2NTI0NzE="

#		http://wiki.mikrotik.com/wiki/Manual:Scripting
#		http://wiki.mikrotik.com/wiki/Manual:Scripting-examples
#		http://wiki.mikrotik.com/wiki/Manual:Tools/Fetch
#		http://forum.ixbt.com/topic.cgi?id=14:60498-86#2373

##############Script FreeDNS.afraid.org##################

The script may not work if you set not all policy in schedule.

/system scheduler
add disabled=no interval=1m name=freedns.afraid.org on-event="/system script run freedns.afraid.org" policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-time=startup

Add-ons for Script

Color log messages

RED — log error (“Service Dynamic DNS: old IP address $“dns-domain-ip” for $“dns-domain” CHANGED to → $“current-ip””)

BLUE — :log warning (“IP address is NOT CHANGED, the update is not required”)