freedns.afraid.org Script

How can a mikrotik router do an automatic update of the public ip address via script?

I’m using the service from “freedns.afraid.org” (e.g. myprivatecomputer.chickenkiller.com)

I guess I can not simply use the script from “http://wiki.mikrotik.com/wiki/Dynamic_DNS_Update_Script_for_dynDNS
and replace the first three lines ??

I’m running v6.10 on my mikrotik router.

Thanks for you help

I’ve never used “freedns.afraid.org”.
I use “no-ip.com” (“.biz” domain).
I’ll show my script.

System-Scripts:
Name: noip
Policy: write,test,read
Source:

##############Script Settings##################

:local NOIPUser "WriteHereName"
:local NOIPPass "WriteHerePassword"
:local WANInter "WriteHereWanInterfaceName"

###############################################

:local NOIPDomain "$NOIPUser.no-ip.biz"
:local IpCurrent [/ip address get [find interface=$WANInter] address];
:for i from=( [:len $IpCurrent] - 1) to=0 do={ 
  :if ( [:pick $IpCurrent $i] = "/") do={ 
    :local NewIP [:pick $IpCurrent 0 $i];
    :if ([:resolve $NOIPDomain] != $NewIP) do={
      /tool fetch mode=http user=$NOIPUser password=$NOIPPass url="http://dynupdate.no-ip.com/nic/update\3Fhostname=$NOIPDomain&myip=$NewIP" keep-result=no
      :log info "NO-IP Update: $NOIPDomain - $NewIP"
     }
   } 
}

Then create shedule:
System-Sheduler:
Name: noip
Start Date: Jan/01/1970
Start Time: 00:00:00
Interval: 00:02:00
On Event: /system script run noip
Policy: write,test,read

Because of free-account and rarely changing ip-address I would have to visit a no-ip site every twenty days.
Otherwise the account will be blocked.
But I made a second script. It sends fake-ip-address (192.168.1.1) every sunday in 01:15am.
Now I can forget about the inconvenience.

System-Scripts:
Name: fake-noip
Policy: write,test,read
Source:

##############Script Settings##################

:local NOIPUser "WriteHereName"
:local NOIPPass "WriteHerePassword"
:local WANInter "WriteHereWanInterfaceName"

###############################################

:local NOIPDomain "$NOIPUser.no-ip.biz"
:local IpCurrent [/ip address get [find interface=$WANInter] address];
:for i from=( [:len $IpCurrent] - 1) to=0 do={ 
  :if ( [:pick $IpCurrent $i] = "/") do={ 
    :local NewIP [:pick $IpCurrent 0 $i];
      /tool fetch mode=http user=$NOIPUser password=$NOIPPass url="http://dynupdate.no-ip.com/nic/update\3Fhostname=$NOIPDomain&myip=192.168.1.1" keep-result=no
      :log info "FAKE NO-IP Update: Done! $NOIPDomain - 192.168.1.1"
   } 
}

Then create shedule:
System-Sheduler:
Name: fake-noip
Start Date: Feb/23/2014
Start Time: 01:15:00
Interval: 7d 00:00:00
On Event: /system script run fake-noip
Policy: write,test,read

By :local WANInter “WriteHereWanInterfaceName”

What name must i set there? the name from ether1 for example?

The fake ip makes that you do not need to visit their re-activation page?

I am using DNSExit. They do not want to keep alive the service by doing regular exercises like no-ip. For them it is enough to put their tiny button somewhere at your webpage. And they checked it for the first time in my case after maybe 3 years of using their service. Then they stopped my service. So I put the button “somewhere” and point them to it (via e-mail), they were happy and I have not seen any hassle with them anymore.

I use name “pppoe2-isp2”
If you don’t use a ppp-session you need to use name of interface - ether1 etc.

exactly.

Is there anybody who have a working script for freedns.afraid.org ?

I’m not very familar with creating scripts …

Thanks

This one works for me

According to http://freedns.afraid.org/signup/moreinfo/ “…For users that want to host their site off their home dial-up connection / cable modem / DSL or equivalent, a special fetchable URL to auto-update the network address in FreeDNS is available in the ‘Dynamic DNS’ section for those whose IP address changes at random…”

Change user_name, password, WAN_interface_name and domain_name with yours, get your particular fetchable URL from Dynamic DNS menu and enter it as an argument in /tool fetch command below (it should look something like hp://freedns.afraid.org/dynamic/update.php?MB34Mlp12asdc1FvWjNsakFGdlUmWQlYOjExMIA1Njg6, hp being http of course)

If you like, enter it in scheduler
/system scheduler
add interval=5m name=Afraid.org on-event=“/system script run Afraid.org

*-where Afraid.org is the script name

:global AfraidUser "user_name"
:global AfraidPass "password"
:global WANInter "interface_name"
:global AfraidDomain "domain_name"

:global IpCurrent [/ip address get [find interface=$WANInter] address];
:for i from=( [:len $IpCurrent] - 1) to=0 do={ 
  :if ( [:pick $IpCurrent $i] = "/") do={ 
    :global NewIP [:pick $IpCurrent 0 $i];
    :if ([:resolve $AfraidDomain] != $NewIP) do={
      /tool fetch mode=http url="fetchable_URL_goes_here" keep-result=no
      :log info "Afraid.org Update: $AfraidDomain - $NewIP"
     } else={
     :log info "Afraid.org: don't need updates";
    }
   } 
}

I am attempting to set up and run the script given in the prior post by a.devecerski and the router does not seem to be saving the script. It keeps popping up a notice saying ‘Could not save script’ and something about a 13 second timeout. A few times while trying to set up the script it would drop me to the login screen.

My goal is to set up port forwarding, but it won’t be very useful if I can’t find home from the outside.

Can someone give a more detailed walkthrough of setting this up?

Thank you.

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”)

I have had problems getting scripts onto the router, I have version 5.26 and everything so far has failed. Does the web console work for this, or would it be better to SSH in (in which case, best way to edit?)?

Does it run at startup or as timed event? What permissions does it require?

Everything else has been easy up to this point.

Use WinBox to create the script.

No need to use or debug the script in the console. The script 100% working condition :

  1. In front of the sign “?” put a backslash "".
  2. If RouterOS version 5.xx, then remove from the URL encryption - “https” change this to “http”.

Read the comments in the script.



/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

Thanks, works fine for me.

WinBox v6.19 on RB951G-2HnD

I think this may have been the problem I was having earlier.

I am pretty sure I have it working now, won’t know for certain until IP changes. I was able to use the web console, just drag into the ‘source’ box and edit for the personal links. This time it saved without error and appears to be working.

Thanks!

LESHIYODESSA: thank you! your script worked perfect for me.

at the begining i was in a hurry and i did’t pay attention to guides/comments; today i read letter by letter, I made the corresponding changes and then it worked! kind of magic! :sunglasses:

As always, read de fu! manual!

Thanks again!

by the way, this script does not appear at mikrotik/agraid.org references and it would be great if it was there: “NOTE: If you’ve written a client, or have added afraid.org support to your product, please drop me a note so I can add it to the supported clients list. dnsadmin@afraid.org

I have already written to dnsadmin@afraid.org, but received no response.

Hurrah!!!

Joshua Anderson added my script on the official site.

There was a misunderstanding, my first letter to it didn’t reach.

Josh is very cool guy, and his service is the coolest of all Dynamic DNS.

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”)

I’m using the service from “freedns.afraid.org” (e.g. myprivatecomputer.chickenkiller.com)

I’ve never used “freedns.afraid.org”.
I use “no-ip.com” (“.biz” domain).
I’ll show my script.

The others aren’t working properly for me anymore. I’ve updated the earlier one to my needs. This script below now works for me from behind another router (DMZ) even!
Please don’t abuse the External Public IP source by running this constantly.
It’s just so I can find it for administration, and not as a public access, so about 30+ minutes is likely good enough for the scheduling part. Besides the TTL for the domain I’m using at Afraid is an hour (3600) so greater then 30 minutes makes sense.

You’ll need to set your afraidDomain and the domainUpdateLink
The domain update link has a cryptic string that’s unique for each record.
It’s hidden slightly in their relatively newer Version 2 (prefered method #1 Randomized Update Token)
http://freedns.afraid.org/dynamic/v2/
With this script you could probably use different links and/or provider.

Note: the main difference here is it finds a Public IP via ICanHazIP.com so if you’re behind another router it still works.
Since the Public IP is the one needed to access via Dynamic DNS it’s the right one to make sure is registered.

# Author: MasterJames 
# Date:   2016:06:10
# Corp:   SparcAsia Holdings Inc.

:global afraidDomain "yourCustom.AfraidDomain.top"
:global domainUpdateLink "http://sync.afraid.org/u/CrypticV2UpdateStringFromAfraidOrg/"

/tool fetch url="http://icanhazip.com/" dst-path="/whatsMyIP.txt";
:global pubIP [/file get whatsMyIP.txt contents]

:for i from=( [:len $pubIP] - 1 ) to=0 do={ 
  :if ( [:pick $pubIP $i] = "\n") do={ 
    :global curIP [:pick $pubIP 0 $i];
    :if ([:resolve $afraidDomain] != $curIP) do={
      /tool fetch url="$domainUpdateLink" keep-result=no;
      :log info "Afraid.org Update: $afraidDomain - $curIP";
    } else={
      :log info "Afraid.org: does NOT need updating: $curIP";
    }
  } 
}