Community discussions

MikroTik App
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 122
Joined: Wed Dec 17, 2014 11:44 am
Location: the land of the long white cloud
Contact:

Updating HE.NET Dynamic DNS

Fri Feb 20, 2015 12:03 pm

Hi,

Could you please help fix my script below:
# Update Hurricane Electric DDNS IPv4 address


:local ddnshost "some.host.name"
:local key "secret"
:local updatehost "dyn.dns.he.net"
:local outputfile ("HE_DDNS" . ".txt")

# Internal processing below...
# ----------------------------------
:local ipv4addr

# Get WAN interface IP address
:set ipv4addr [/ip address get [/tool fetch url="http://myip.dnsomatic.com/" mode=http] address]
:set ipv4addr [:pick [:tostr $ipv4addr] 0 [:find [:tostr $ipv4addr] "/"]]

:log info ("Updating DDNS IPv4 address" . " Client IPv4 address to new IP " . $ipv4addr . "...")

/tool fetch url="http://$ddnshost:$key@$updatehost/nic/update?hostname=$ddnshost&myip=$ipv4addr"  \
dst-path=$outputfile

:log info ([/file get ($outputfile) contents])
#/file remove ($outputfile)
The problem is my router WAN interface is using local IP, so my router need to read IP address from 3rd party site (I mentioned above on my script) but it doesn't work, anyone has idea to fix this script?

Thank you and I love hearing from you soon.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Updating HE.NET Dynamic DNS

Fri Feb 20, 2015 3:51 pm

What is this?
:set ipv4addr [/ip address get [/tool fetch url="http://myip.dnsomatic.com/" mode=http] address]
:set ipv4addr [:pick [:tostr $ipv4addr] 0 [:find [:tostr $ipv4addr] "/"]]
It's all wrong.
/tool fetch mode=http upload=no url="http://myip.dnsomatic.com/" keep-result=yes dst-path="myip.txt";
:delay delay-time=3s;
:set ipv4addr [/file get myip.txt value-name=contents];
/file remove myip.txt;
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 122
Joined: Wed Dec 17, 2014 11:44 am
Location: the land of the long white cloud
Contact:

Re: Updating HE.NET Dynamic DNS

Sat Feb 21, 2015 12:09 am

What is this?
:set ipv4addr [/ip address get [/tool fetch url="http://myip.dnsomatic.com/" mode=http] address]
:set ipv4addr [:pick [:tostr $ipv4addr] 0 [:find [:tostr $ipv4addr] "/"]]
It's all wrong.
/tool fetch mode=http upload=no url="http://myip.dnsomatic.com/" keep-result=yes dst-path="myip.txt";
:delay delay-time=3s;
:set ipv4addr [/file get myip.txt value-name=contents];
/file remove myip.txt;
Hi, thanks for your reply, I tried to modify my script like this:
# Update Hurricane Electric DDNS IPv4 address


:local ddnshost "some.host.name"
:local key "secret"
:local updatehost "dyn.dns.he.net"

# Internal processing below...
# ----------------------------------
:local ipv4addr

# Get WAN interface IP address
/tool fetch mode=http upload=no url="http://myip.dnsomatic.com/" keep-result=yes dst-path="myip.txt";
:delay delay-time=3s;
:set ipv4addr [/file get myip.txt value-name=contents];

:log info ("Updating DDNS IPv4 address" . " Client IPv4 address to new IP " . $ipv4addr . "...")

/tool fetch url="http://$ddnshost:$key@$updatehost/nic/update?hostname=$ddnshost&myip=$ipv4addr"  \
dst-path="myip.txt

:log info ([/file get "myip.txt" contents])
/file remove "myip.txt";
But it's still not working, any other clue?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Updating HE.NET Dynamic DNS

Sat Feb 21, 2015 11:47 am

First of all: DNS and Internet must work:
:ping [:resolve http://www.google.com];

I can fix the script, but I can't test it, i do not have that service.
If you want test some scripts on terminal, put everytime all script between { } and put "\" before "?"

If you put that on script or scheduler or wathever, remember to remove the "\" before "?" !!!
{
:local ddnshost value="some.host.name";
:local key value="secret";
:local updatehost value="dyn.dns.he.net";

/tool fetch mode=http upload=no url="http://myip.dnsomatic.com/" keep-result=yes dst-path="myip.txt";
:delay delay-time=3s;
:local ipv4addr value=[/file get "myip.txt" value-name=contents];
/file remove "myip.txt";
:log info message=("Updating DDNS IPv4 address - Client IPv4 address to new IP ".$ipv4addr."...");

# I can not test this line, I do not have that service
/tool fetch mode=http upload=no keep-result=yes dst-path="hereply.txt" \
url=("http://".$ddnshost.":".$key."@".$updatehost."/nic/update\?hostname=".$ddnshost."&myip=".$ipv4addr);

:delay delay-time=3s;
:log info message=("Updating DDNS IPv4 address - Server reply: ".[/file get "hereply.txt" value-name=contents]);
/file remove "hereply.txt";
}
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 122
Joined: Wed Dec 17, 2014 11:44 am
Location: the land of the long white cloud
Contact:

Re: Updating HE.NET Dynamic DNS

Sat Feb 21, 2015 9:36 pm

First of all: DNS and Internet must work:
:ping [:resolve http://www.google.com];

I can fix the script, but I can't test it, i do not have that service.
If you want test some scripts on terminal, put everytime all script between { } and put "\" before "?"

If you put that on script or scheduler or wathever, remember to remove the "\" before "?" !!!
{
:local ddnshost value="some.host.name";
:local key value="secret";
:local updatehost value="dyn.dns.he.net";

/tool fetch mode=http upload=no url="http://myip.dnsomatic.com/" keep-result=yes dst-path="myip.txt";
:delay delay-time=3s;
:local ipv4addr value=[/file get "myip.txt" value-name=contents];
/file remove "myip.txt";
:log info message=("Updating DDNS IPv4 address - Client IPv4 address to new IP ".$ipv4addr."...");

# I can not test this line, I do not have that service
/tool fetch mode=http upload=no keep-result=yes dst-path="hereply.txt" \
url=("http://".$ddnshost.":".$key."@".$updatehost."/nic/update\?hostname=".$ddnshost."&myip=".$ipv4addr);

:delay delay-time=3s;
:log info message=("Updating DDNS IPv4 address - Server reply: ".[/file get "hereply.txt" value-name=contents]);
/file remove "hereply.txt";
}
Hi again, thank you for your reply, I tried this script:
:local ddnshost value="some.host.name";
:local key value="secret";
:local updatehost value="dyn.dns.he.net";

/tool fetch mode=http upload=no url="http://myip.dnsomatic.com/" keep-result=yes dst-path="myip.txt";
:delay delay-time=3s;
:local ipv4addr value=[/file get "myip.txt" value-name=contents];
/file remove "myip.txt";
:log info message=("Updating DDNS IPv4 address - Client IPv4 address to new IP ".$ipv4addr."...");

# I can not test this line, I do not have that service
/tool fetch mode=http upload=no keep-result=yes dst-path="hereply.txt" url=("http://".$ddnshost.":".$key."@".$updatehost."/nic/update\?hostname=".$ddnshost."&myip=".$ipv4addr);

:delay delay-time=3s;
:log info message=("Updating DDNS IPv4 address - Server reply: ".[/file get "hereply.txt" value-name=contents]);
/file remove "hereply.txt";
Run it on scheduler, but still not working.
And what do you mean by "I can not test this line, I do not have that service" ?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Updating HE.NET Dynamic DNS

Sun Feb 22, 2015 1:29 am

remember to remove the "\" before "?" !!!
I do not have that service = i not have one account on hurricane to test
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 122
Joined: Wed Dec 17, 2014 11:44 am
Location: the land of the long white cloud
Contact:

Re: Updating HE.NET Dynamic DNS

Sun Feb 22, 2015 5:31 am

remember to remove the "\" before "?" !!!
I do not have that service = i not have one account on hurricane to test
I fixed to be like this:
But same, still not working.
:local ddnshost value="some.host.name";
:local key value="secret";
:local updatehost value="dyn.dns.he.net";

/tool fetch mode=http upload=no url="http://myip.dnsomatic.com/" keep-result=yes dst-path="myip.txt";
:delay delay-time=3s;
:local ipv4addr value=[/file get "myip.txt" value-name=contents];
/file remove "myip.txt";
:log info message=("Updating DDNS IPv4 address - Client IPv4 address to new IP ".$ipv4addr."...");

# I can not test this line, I do not have that service
/tool fetch mode=http upload=no keep-result=yes dst-path="hereply.txt" url=("http://".$ddnshost.":".$key."@".$updatehost."/nic/update?hostname=".$ddnshost."&myip=".$ipv4addr);

:delay delay-time=3s;
:log info message=("Updating DDNS IPv4 address - Server reply: ".[/file get "hereply.txt" value-name=contents]);
/file remove "hereply.txt";
However this script is working, but updating my LAN IP (because my router's WAN interface is using LAN IP)
# Update Hurricane Electric DDNS IPv4 address


:local ddnshost "some.host.name"
:local key "secret"
:local updatehost "dyn.dns.he.net"
:local WANinterface "ether1-GTW"
:local outputfile ("HE_DDNS" . ".txt")

# Internal processing below...
# ----------------------------------
:local ipv4addr

# Get WAN interface IP address
:set ipv4addr [/ip address get [/ip address find interface=$WANinterface] address]
:set ipv4addr [:pick [:tostr $ipv4addr] 0 [:find [:tostr $ipv4addr] "/"]]

:if ([:len $ipv4addr] = 0) do={
   :log error ("Could not get IP for interface " . $WANinterface)
   :error ("Could not get IP for interface " . $WANinterface)
}

:log info ("Updating DDNS IPv4 address" . " Client IPv4 address to new IP " . $ipv4addr . "...")

/tool fetch url="http://$ddnshost:$key@$updatehost/nic/update?hostname=$ddnshost&myip=$ipv4addr"  \
dst-path=$outputfile

:log info ([/file get ($outputfile) contents])
/file remove ($outputfile)
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 122
Joined: Wed Dec 17, 2014 11:44 am
Location: the land of the long white cloud
Contact:

Re: Updating HE.NET Dynamic DNS

Mon Feb 23, 2015 11:41 am

*bump*
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 122
Joined: Wed Dec 17, 2014 11:44 am
Location: the land of the long white cloud
Contact:

Re: Updating HE.NET Dynamic DNS

Tue Feb 24, 2015 12:29 pm

Anybody here..?
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 122
Joined: Wed Dec 17, 2014 11:44 am
Location: the land of the long white cloud
Contact:

Re: Updating HE.NET Dynamic DNS

Wed Feb 25, 2015 1:06 am

*bump*
 
itmethod
newbie
Posts: 34
Joined: Tue Feb 18, 2014 8:44 pm

Re: Updating HE.NET Dynamic DNS

Sat Feb 18, 2017 11:29 am

Here you go this works for me on multiple routers.
# Update Hurricane Electric DDNS IPv4 address


:local ddnshost "your domain here"
:local key "Your Key Here"
:local updatehost "dyn.dns.he.net"
:local WANinterface "ether1-gateway"
:local outputfile ("HE_DDNS" . ".txt")

# Internal processing below...
# ----------------------------------
:local ipv4addr

/tool fetch mode=http url="http://checkip.dns.he.net/" dst-path="/dyndns.checkip.html"
:local result [/file get dyndns.checkip.html contents]

# parse the current IP result
:local resultLen [:len $result]
:local startLoc [:find $result ": " -1]
:set startLoc ($startLoc + 2)
:local endLoc [:find $result "</body>" -1]
:local ipv4addr [:pick $result $startLoc $endLoc]
:log info "UpdateHEDNS: currentIP = $ipv4addr"
#End Get Public IP

:if ([:len $ipv4addr] = 0) do={
   :log error ("Could not get IP for interface " . $WANinterface)
   :error ("Could not get IP for interface " . $WANinterface)
}

:log info ("Updating DDNS IPv4 address" . " Client IPv4 address to new IP " . $ipv4addr . "...")

/tool fetch url="http://$ddnshost:$key@$updatehost/nic/update?hostname=$ddnshost&myip=$ipv4addr"  \
dst-path=$outputfile
                              
:log info ([/file get ($outputfile) contents])
/file remove ($outputfile)
 
User avatar
aaronk6
just joined
Posts: 5
Joined: Tue Mar 14, 2023 11:06 am
Location: Germany

Re: Updating HE.NET Dynamic DNS

Wed Jul 26, 2023 3:05 pm

I know this is an old thread, but since it’s the first result when googling for “mikrotik he.net ddns”, I thought it might be useful to share my version of the script which contains a few improvements:
  • Support for IPv6 (you’ll need to specify an interface and an IPv6 pool)
  • Error handling (i.e. when the IPv6 update fails, the IPv4 will still be published)
  • Does not write temporary files
  • Does not rely on an external service to determine the IP addresss
Here’s the script:
# RouterOS dynamic DNS Update Script for he.net
# =============================================

# make global to preserve IP and IPv6 address across script executions
:global ipddns
:global ipv6ddns

:local ddnshost "myhost.example.com"
:local ddnspass "MY_SECURE_PASSWORD"
:local waninterfacev4 "V4_INTERFACE_NAME" # Interface to retrieve WAN IPv4 address from (i.e. pppoe-out1)
:local waninterfacev6 "V6_INTERFACE_NAME" # Interface to retrieve WAN IPv6 address from (i.e. bridge1)
:local ipv6pool "YOUR_IP6_POOL" # Pool that IPv6 address needs to be part of
:local url "https://dyn.dns.he.net/nic/update"

:local ipfresh ""
:local ipv6fresh ""
:local ipv4error false
:local ipv6error false

:do {
    # get current IP address from WAN interface
    :set ipfresh [/ip address get [find where interface=$waninterfacev4] value-name=address]
    # Check if ipfresh is empty
    :if ($ipfresh = "") do={
        :log error ("DDNS: Failed to get IP address from interface $waninterfacev4.")
        :set ipv4error true
    }
    :if ([ :typeof $ipfresh ] = nil ) do={
        :log error ("DDNS: No IP address on $waninterfacev4")
        :set ipv4error true
    }
} on-error={
    :log error "DDNS: An error occurred while getting the current IP address from WAN interface."
    :set ipv4error true
}

:do {
    # get current IPv6 address from LAN interface
    :set ipv6fresh [/ipv6/address get [find where from-pool="telekom-ipv6" interface=$waninterfacev6] address]
    # Check if ipv6fresh is empty
    :if ($ipv6fresh = "") do={
        :log error ("DDNS: Failed to get IPv6 address from interface $waninterfacev6.")
        :set ipv6error true
    }
    :if ([ :typeof $ipv6fresh ] = nil ) do={
        :log error ("DDNS: No IPv6 address on $waninterfacev6")
        :set ipv6error true
    }
} on-error={
    :log error "DDNS: An error occurred while getting the current IPv6 address from LAN interface."
    :set ipv6error true
}

# extract the portion of the IP address before the last / character
:do {
    # extract the portion of the IP address before the last / character
    :for i from=( [:len $ipfresh] - 1) to=0 do={ 
        :if ( [:pick $ipfresh $i] = "/") do={ 
            :set ipfresh [:pick $ipfresh 0 $i];
        } 
    }

    :for i from=( [:len $ipv6fresh] - 1) to=0 do={ 
        :if ( [:pick $ipv6fresh $i] = "/") do={ 
            :set ipv6fresh [:pick $ipv6fresh 0 $i];
        } 
    }
} on-error={
    :log error "DDNS: An error occurred while extracting the portion of the IP addresses."
}

:do {
    # Check and update IPv4 address
    :if ($ipv4error) do={
        :log warning "DDNS: Skipping IPv4 update due to previous error."
    } else {
        :if ($ipddns = $ipfresh) do={
            :log info ("DDNS: IP address is already up to date")
        } else {
            :log info ("DDNS: IP address has changed from $ipddns to $ipfresh, sending update...")
            :local body "hostname=$ddnshost&password=$ddnspass&myip=$ipfresh"
            :local result [/tool fetch mode=https output=user url=$url http-method=post http-data=$body as-value]

            :if ($result->"status" != "finished") do={
                :log error ("DDNS: Failed to send IPv4 update")
            } else {
                :log info ("DDNS: Response from server: " . $result->"data")
                :if (([:find ($result->"data") "good"] = 0) or ([:find ($result->"data") "nochg"] = 0)) do={
                    :set ipddns $ipfresh
                }
            }
        }
    }
} on-error={
    :log error "DDNS: An error occurred while checking and updating the IPv4 address."
}

:do {
    # Check and update IPv6 address
    :if ($ipv6error) do={
        :log warning "DDNS: Skipping IPv6 update due to previous error."
    } else {
        :if ($ipv6ddns = $ipv6fresh) do={
            :log info ("DDNS: IPv6 address is already up to date")
        } else {
            :log info ("DDNS: IPv6 address has changed from $ipv6ddns to $ipv6fresh, sending update...")
            :local body "hostname=$ddnshost&password=$ddnspass&myip=$ipv6fresh"
            :local result [/tool fetch mode=https output=user url=$url http-method=post http-data=$body as-value]

            :if ($result->"status" != "finished") do={
                :log error ("DDNS: Failed to send IPv6 update")
            } else {
                :log info ("DDNS: Response from server: " . $result->"data")
                :if (([:find ($result->"data") "good"] = 0) or ([:find ($result->"data") "nochg"] = 0)) do={
                    :set ipv6ddns $ipv6fresh
                }
            }
        }
    }
} on-error={
    :log error "DDNS: An error occurred while checking and updating the IPv6 address."
}
It’s also on GitHub as a Gist.

I’ve tested this on RouterOS 7.9.

Who is online

Users browsing this forum: Bing [Bot] and 29 guests