Community discussions

MikroTik App
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 110
Joined: Wed Dec 17, 2014 11:44 am
Location: Auckland, New Zealand
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.
[ IMikroTik ] >
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2954
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

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;
I'm Italian, not English. Sorry for my imperfect grammar.
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 110
Joined: Wed Dec 17, 2014 11:44 am
Location: Auckland, New Zealand
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?
[ IMikroTik ] >
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2954
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

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";
}
I'm Italian, not English. Sorry for my imperfect grammar.
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 110
Joined: Wed Dec 17, 2014 11:44 am
Location: Auckland, New Zealand
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" ?
[ IMikroTik ] >
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2954
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

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
I'm Italian, not English. Sorry for my imperfect grammar.
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 110
Joined: Wed Dec 17, 2014 11:44 am
Location: Auckland, New Zealand
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)
[ IMikroTik ] >
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 110
Joined: Wed Dec 17, 2014 11:44 am
Location: Auckland, New Zealand
Contact:

Re: Updating HE.NET Dynamic DNS

Mon Feb 23, 2015 11:41 am

*bump*
[ IMikroTik ] >
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 110
Joined: Wed Dec 17, 2014 11:44 am
Location: Auckland, New Zealand
Contact:

Re: Updating HE.NET Dynamic DNS

Tue Feb 24, 2015 12:29 pm

Anybody here..?
[ IMikroTik ] >
 
yacsap
Member Candidate
Member Candidate
Topic Author
Posts: 110
Joined: Wed Dec 17, 2014 11:44 am
Location: Auckland, New Zealand
Contact:

Re: Updating HE.NET Dynamic DNS

Wed Feb 25, 2015 1:06 am

*bump*
[ IMikroTik ] >
 
itmethod
newbie
Posts: 28
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)

Who is online

Users browsing this forum: No registered users and 18 guests