Konstantin Antselovich » routeros http://konstantin.antselovich.com random generator Wed, 25 Feb 2015 01:21:33 +0000 en hourly 1 http://wordpress.org/?v=3.1 Mikrotik + ClouldFlare = DynDNS http://konstant1n.livejournal.com/9759.html http://konstant1n.livejournal.com/9759.html#comments Sun, 06 Oct 2013 20:32:10 +0000 Random Journal http://konstant1n.livejournal.com/9759.html

I got fed up with free service from DynDNS: your record will disappear in 30 days unless you login into their site and "confirm" it. DynDNS annoys you on purpose, so you buy their "pro" service. I do not like being annoyed, and I do not see a point of paying for DynDNS service -- their value proposition is weak, as anyone can create a script that updates DNS records.

I have a website that is protected by ClouldFlare service. ClouldFlare offers an API that can be used to update DNS records, so I wrote a script for Mikrotik RouterOS that does just that.



Note that you need RouterOS v6 ( as fetch command supports https only since version 6.0rc12


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

:local CFemail "clouldflare email login "
:local CFtkn "api access token"
:local CFzone "clouldflare website, example: example.com"
:local CFid "dns record id, available via rec_load_all API call, example: 12345"
:local CFtype "A"
:local CFttl "300"
:local CFservicemode "0"
:local CFDomain "FQDN DNS record that you will be updating, example: myhomeip.exmaple.com"

############## Build CF API Url ################
:local CFurl "https://www.cloudflare.com/api_json.html\3F"
:set CFurl ($CFurl . "a=rec_edit&tkn=$CFtkn&id=$CFid");
:set CFurl ($CFurl . "&email=$CFemail&z=$CFzone&type=$CFtype");
:set CFurl ($CFurl . "&name=$CFDomain&service_mode=$CFservicemode&ttl=$CFttl");

:local WANInter "name of the outing network interface on mikrotik router, example: ether1-gateway"

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

: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 $CFDomain] != $NewIP) do={
:log info "Will update: $NewIP"
/tool fetch mode=https url="$CFurl&content=$NewIP" keep-result=no
:log info "CF Update: $CFDomain - $NewIP"
}
}
}





http://www.cloudflare.com/docs/client-api.html
http://wiki.mikrotik.com/wiki/Manual:Scripting]]>
http://konstantin.antselovich.com/archives/2013/10/06/mikrotik-clouldflare-dyndns/feed/ 0
Mikrotik + ClouldFlare = DynDNS https://konstant1n.livejournal.com/9759.html https://konstant1n.livejournal.com/9759.html#comments Sun, 06 Oct 2013 20:32:10 +0000 konstant1n https://konstant1n.livejournal.com/9759.html

I got fed up with free service from DynDNS: your record will disappear in 30 days unless you login into their site and "confirm" it. DynDNS annoys you on purpose, so you buy their "pro" service. I do not like being annoyed, and I do not see a point of paying for DynDNS service -- their value proposition is weak, as anyone can create a script that updates DNS records.

I have a website that is protected by ClouldFlare service. ClouldFlare offers an API that can be used to update DNS records, so I wrote a script for Mikrotik RouterOS that does just that.



Note that you need RouterOS v6 ( as fetch command supports https only since version 6.0rc12


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

:local CFemail "clouldflare email login "
:local CFtkn "api access token"
:local CFzone "clouldflare website, example: example.com"
:local CFid "dns record id, available via rec_load_all API call, example: 12345"
:local CFtype "A"
:local CFttl "300"
:local CFservicemode "0"
:local CFDomain "FQDN DNS record that you will be updating, example: myhomeip.exmaple.com"

############## Build CF API Url ################
:local CFurl "https://www.cloudflare.com/api_json.html\3F"
:set CFurl ($CFurl . "a=rec_edit&tkn=$CFtkn&id=$CFid");
:set CFurl ($CFurl . "&email=$CFemail&z=$CFzone&type=$CFtype");
:set CFurl ($CFurl . "&name=$CFDomain&service_mode=$CFservicemode&ttl=$CFttl");

:local WANInter "name of the outing network interface on mikrotik router, example: ether1-gateway"

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

: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 $CFDomain] != $NewIP) do={
:log info "Will update: $NewIP"
/tool fetch mode=https url="$CFurl&content=$NewIP" keep-result=no
:log info "CF Update: $CFDomain - $NewIP"
}
}
}





http://www.cloudflare.com/docs/client-api.html
http://wiki.mikrotik.com/wiki/Manual:Scripting]]>
http://konstantin.antselovich.com/archives/2013/10/06/mikrotik-clouldflare-dyndns-2/feed/ 0
MikroTik RouterOS • View topic – QoS: Skype http://forum.mikrotik.com/viewtopic.php?f=9&t=45209 http://forum.mikrotik.com/viewtopic.php?f=9&t=45209#comments Sat, 26 Mar 2011 08:00:10 +0000 konstant1n http://www.delicious.com/url/67da9f31a4880e803c2c39adea9329f3#konstant1n http://feeds.delicious.com/v2/rss/url/67da9f31a4880e803c2c39adea9329f3 0