About Dynamic DNS

1.How to make DynamicDNS-tool
2.Get IP-address from router
3.Report IP-address to dynamicDNS-support-site
4.This is the tool
5.Some hints
6.File showed in this page
7.By scheme
8.About BL900HW-router
9.About BL900HW-router by scheme
10.dynamicDNS tool of NVR500 (YAMAHA router)

1. The method of makeing Dynamic DNS tool

1-1. Two kind of approaches

If IP-address of your site changes then dynamic DNS tool reports this fact (changing address) to related site.
There are two kind of approaches.

The method 1) is not sophisticated. So you shoudl take method 2) !!



1-2. Procedure to make tool

The procedure is

That's all. Let's make the tool.



2.Get IP-address from router

I assume that you use router to access INTERNET.
The question is how to get IP-address from the router.The easiest way is to use wget command in UNIX. I explain by using my router (NEC BL150HV).
Normal method to manage this router is to use browser.
If you access to the router by your browser, you can see below. (for example in Win XP)


this is bacic auth

It is basic authencication. In this case, you can get data from router by useing wget command like this.

$ wget -O log --http-user=hoge --http-passwd=funya 'http://$URL'

$URL is the IP-address of router in your LAN (for example my router is 192.168.10.1). "hoge" means user-ID. "funya" means your passwd to the router
This command can get data into current file named "log". But you can not get IP-address here.
You should know the URL of the router first. In case of BL150HV, URL that shows IP-address is..

info_main.html

This is the IP-address page URL. So,,,,

$ wget -O log --http-user=hoge --http-passwd=funya 'http://$URL/info_main.html'

This command gets data which includes your IP-address from router.
Now we have to take just only IP-address from this file.
If you look at this file carefully, you will find the line which contains the word below.

msgShow(event,24)

The next line of above line contains IP-address. So we have to read until the line contains above word. The next line is the target line. Let's use perl.

$file = "./log";
open DATA, $file || die;
while(defined ($str = <DATA>)){
    if($str =~ /msgShow\(event,24\)/){
    $str = <DATA>;
    last;
  }
}
close DATA || die;

Above program get the target line and seve it to $str. This target line is shown below.

<TD>59.139.153.201\201@</TD>

Then let's pick up just only IP-address from above $str.

$file = "./log";
open DATA, $file || die;
while(defined ($str = <DATA>)){
    if($str =~ /msgShow\(event,24\)/){
        $str = <DATA>;
        $str =~ s/ +<TD>//;
        $str =~ s/\201@<\/TD>\n//;
        last;
    }
}
close DATA || die;

Now, $str contains just only IP-address without \n. So you should write this down to some file.
Next, Let's compare new file that contains newly gotten IP-address and old file that contains IP-address gotten before.
If two files are different, then you should report it to provider !
The method to compare two files is shown below.

$ diff  ./log  ./before-log

It is easy to compare two files.(^^)


3. The method to report IP-address to the provider

May be, you can get the reporting method from your provider's web-site. Value-domain (my provider) shows the method below. I have to use wget command again.

$ wget http://dyn.value-domain.com/cgi-bin/dyn.fcg?d=$dm&p=$pw&h=*&i=$ip

d=$dm is the domain name. p=$pw is the passwd. h=* meens host name. But you need just only *. i=$ip shows IP-adddress. But if you don't use proxy, you don't need &i=$ip part.



4. The tool

Finished tool (ddns-tool) is shown below.

#!/usr/bin/perl  -w
#
# ddns-tool
#
####################################
# get IP address from BL-150HV
####################################
$workdir =  "/var/ddns";
$passwd  =  "*********";                 # your router password
$userid  =  "admin"                      # your router user-id
$rtip    =  "http://192.168.10.1/info_main.html";   # your router URL
$file    =  "./tmp-log";
$wgetpath = "/usr/local/bin/wget";       # your wget path

chdir  $workdir  || die;

if(-e $file){
  unlink  $file  || die;
}

system "$wgetpath -q -O $file --http-user=$userid --http-passwd=$passwd $rtip";

open DATA, $file  ||  die;
while(defined ($str = <DATA>)){
   if($str = ~/msgShow\(event,24\)/){
        $str = <DATA>;
        $str = ~s/ +<TD>//;
        $str = ~s/\201@<\/TD>\n//;
        last;
   }
}
close  DATA  ||  die;

unlink  $file;
open  DATA,  ">".$file  ||  die;
print DATA  $str;
close DATA  ||  die; 
 
################################################ 
# compare both ip 
# and update webpage if IP-address is changed 
################################################ 
 
$ipfile =  "./ip-file"; 
$dm =  "*******";  # your domainname 
$pw =  "*********";# your ddns provider password 
 
if(system("diff $ipfile $file >/dev/null 2>&1")){ 
  unlink $ipfile; 
  rename $file $ipfile; 
  update_web (); 
}else{ 
  unlink $file; 
  if($ARGV[0] && ($ARGV[0] =~/-f/i)){ 
    update_web (); 
  } 
} 
 
######################################## 
# update  provider  web pag sub program 
# for value-domain ddns 
######################################## 
 
sub update_web { 
  open DATA, $ipfile || die; 
  $ip = <DATA>; 
  system "$wgetpath -q -O log 'http://dyn.value-domain.com/cgi-bin/dyn.fcg?d=$dm&p=$pw&h=*&i=$ip'"; 
  close DATA || die; 
} 

I use /var/ddns working directory. First you have to make some file (ip-file). Any contents will do. For example

$ echo "hoge" > ip-file

This is ok!
If you type "$ ddns-tool(return)" the tool report IP-address just only when address changed.
But if you type "$ ddns-tool -f (return)" the tool report IP-address no matter address changed or not.
This is because some provider delete the account of the user if the user does not report IP-address so long (Exmple 2 .. 3 months)
Next let's compile /etc/crontab as shown below. And copy ddns-tool to /usr/local/sbin drectory.

5     *   *   *   *   /usr/local/sbin/ddns-tool
3     5   5   *   *   /usr/local/sbin/ddns-tool  -f

First line means once in an hour (5 minutes past some hour), ddns-tool checks IP-address and report address if it has been changed.
Second line means that ddns-tool reports IP-address at 3 minites past 5 oclock on the 5th day of every month.


5. Several hints

5-1. Another routers

As shown above, to get IP-address from router is the most troublesome part of this program.
So, I show this part for other routers below. I show YAMAHA-RT57i, Linksys-BEFSR41C, Allied-telesys-AR230E.
Please replace this part from above program. And I recommend you to challeng other routers. Perhaps you can do it.

----------------------------------
      YAMAHA RT57i
---------------------------------- 
 
$file = "./tmp-log"; 
$uid = "";                                        #Your user id (may be ,,,blank) 
$pass = "*********";                              #Your password here! 
$rtip = "http://*****/detail/status.html";        #Your router address 
 
if(-e $file){ 
    unlink $file || die; 
} 
 
!system("/usr/local/bin/wget -q -O $file --http-user=$uid --http-passwd=$pass $rtip" ) || die; 
 
open  DATA,  $file  ||  die; 
for($i  =  0; $tmp  =  <DATA>; $i++){ 
    if($tmp =~/IP  address/){ 
    last; 
    } 
} 
close  DATA  ||  die; 
 
unlink  $file  ||  die; 
open  DATA  ">".$file  ||  die; 
 
chop ($tmp); 
chop ($tmp); 
$tmp =~ / +IP address: //; 
$tmp =~ /\/22//; 
 
print DATA $tmp; 
close DATA || die; 
 
 
 


------------------------------------ 
     Linksys BEFSR-41C 
------------------------------------ 
$passwd = "********";                        #password here! 
$userid = "";                                #Your user id here!( may be,,,,blank ) 
$rtip   = "http://********/Status.htm";      #router address 
$file   = "./tmp-log"; 
 
if(-e  $file){ 
  unlink  $file  ||  die "Can not unlink $file\n"; 
} 
 
!system ("/usr/local/bin/wget -q -O $file --http-user=$userid --http-passwd=$passwd $rtip") || die "Cant system wget\n"; 
 
open  HD, "+<",$file  ||  die; 
$tmp  =  <HD>; 
@field =  split(/bgcolor=/,$tmp); 
$tmp  =  $field[26]; 
@field = split(/verdana/,$tmp); 
$tmp  =  $field[2]; 
@field = split(/size=2>/,$tmp); 
$tmp  =  $field[1]; 
@field  =  split(/<\/td>/,$tmp); 
$tmp  =  $field[0]; 
seek (HD,0,0); 
truncate (HD,0); 
print HD $tmp; 
close  HD  ||  die; 
 
 
 

--------------------------------------- 
    Allied-telesys AR-230E 
--------------------------------------- 
$passwd = "********";                            # Your password here! 
$userid = "root";                                # user id (fixed) 
$rtip   = "http://*******/_SystemInfo.htm";      # ****** is your router address 
$file2  = "./tmp-log2"; 
$file   = "./tmp-log"; 
 
if(-e  $file2){ 
  unlink  $file  ||  die; 
} 
if(-e  $file){ 
  unlink  $file  ||  die; 
} 
 
!system ("/usr/local/bin/wget -q -O $file2 --http-user=$userid --http-passwd=$passwd $rtip") || die; 
!system("./toprint <  $file2  >$file") ||  die;  # remove non-graphical characters 
unlink  $file2  ||  die; 
 
open  DATA, "+<", $file  ||  die; 
$str = <DATA>; 
@tmp = split(/<B>IPAhX<\/B> : /, $str); 
$str = $tmp[2]; 
@tmp = split(/<br><B>Tulbg}XN<\/B>/, $str); 
$str = $tmp[0]; 
 
seek (DATA, 0, 0); 
truncate (DATA, 0); 
 
print DATA  $str; 
 
close  DATA  ||  die; 

Toprint program remove characters which can't be displaied.

#include  <stdio.h> 
#include  <ctype.h> 
 
/**for router AR230E ***/ 
/**cc -o toprint      **/ 
 
int main(void){ 
  int c; 
  while((c = getchar()) != EOF){ 
    if(isprint(c)) 
      putchar(c); 
  } 
  return 0; 
} 


5-2. If you use UNIX PPPoE instead of router

It's easy. You should do ifconfig command and take IP-address from result of that command.
In FreeBSD ...

#!/usr/bin/perl -w 
$if = "em0";                  # your Ethernet interface 
$file = "tmp-log"; 
 
system  "ifconfig $if  >  $file"; 
open  HD, $file  ||  die; 
while ($str = <HD>){ 
  if($str =~/inet /){ 
    last; 
  } 
} 
close  HD  ||  die; 
unlink  $file  ||  die; 
 
open HD, ">".$file  ||  die; 
@fields = split (/inet /, $str); 
shift @fields; 
$str = $fields[0]; 
@fields = split (/ netmask/, $str); 
$str = $fields[0]; 
print HD $str; 
close  HD  ||  die; 

That's all.





5-3. If you can't take IP-address from your router.

OK. You can ask your IP-address to some website.
These sites may teach you your IP-address.

http://checkip.dyndns.org/
http://info.ddo.jp/remote_addr.php/
https://ipdetect.dnspark.com/

For example, first website, please do that.

$ wget  -O log http://checkip.dyndns.org/

Then....

<html><head><title>Current IP Check</title></head><body>Current IP Address: 59.139.153.201</body></html>

You can get this log above. You can find your IP-address in this log. You shoule take proper part(IP-address) from this log. I show script below.

#!/usr/bin/perl -w
$file = "./tmp-log";

!system( "wget -q -O $file 'http://checkip.dyndns.org/'")  ||  die; 
open  HD, $file  ||  die; 
$str = <HD>; 
close  HD  ||  die; 
unlink  $file  ||  die; 
@fields = split(/IP Address: /, $str); 
shift  @fields; 
$str = $fields[0]; 
@fields = split(/<\/body>/, $str); 
$str = $fields[0]; 
open  HD,  ">".$file  ||  die; 
print  HD  $str; 
close  HD; 

Please replace this script from the program.




6. The program(script) that I showed in this chapter

Here is the script. No warranty but you can use this.
If your computer has perl interpreter, perhaps you can use this.




7. Same program (srcipt) written in scheme.

Here I show same program written in Scheme.
I use SCM this time.


#!/usr/local/bin/scm
(require 'i/o-extensions)
(load "/usr/include/mystring.scm")
;                                                                                    
(define $cmd1  "wget -q -O tmp-file --http-user=")
(define $usr-id "admin  ")
(define $cmd2  "--http-passwd=")
(define $pass   "********  ") ;; < ----------------- Your router passwd. Last character should be one space.
(define $url  "http://192.168.10.1/info_main.html") ;;< --- Your router url
(define $work-dir "/var/ddns") ;; < ------------- Working directory
;                                                                                    
(chdir $work-dir)
(system (string-append $cmd1 $usr-id $cmd2 $pass $url))
;                                                                                    
(define $file "tmp-file")
(define $back (string #\x81 #\x40 #\x3c))
;                                                                                    
(define in-port (open-input-file $file))
;                                                                                    
(call/cc (lambda (return)
  (do
    (($word (read-line in-port) (read-line in-port)))
    ((eof-object? $word) (exit))
        (if (and (string? $word) (string-contains $word "msgShow(event,24)")) (return 0)))))
;                                                                                    
(define $word (read-line in-port))
(close-input-port in-port)
(delete-file $file)
;                                                                                    
(define out-port (open-output-file $file))
(define nn (string-contains $word $back))
(set! $word (substring $word 8 nn))
(display $word out-port)
(close-output-port out-port)
;                                                                                    
;                                                                                    
(define $pw "**********") ;; < ------------- Your providers passwd (That provider serve you DDNS service)
(define $dm "quinos.net") ;; < -------------- Your domain name
(define $cmd (string-append "wget -q -O log 'http://dyn.value-domain.com/cgi-bin/dyn.fcg?d=" $dm "&p=" $pw "&h=*&i=" $word "'"))

(define $ip-file "ip-file")
(define ip-port (open-input-file $ip-file))
(define $ip (read-line ip-port))
(close-input-port ip-port)
;                                                                                    
;                                                                                    
(cond
 ((or (eof-object? $ip) (not (string=? $ip $word)))
  (delete-file $ip-file)
  (system (string-append "mv " $file " " $ip-file))
  (system $cmd))
 ((and (not (null? (cddr *argv*))) (string=? (caddr *argv*) "-f"))
  (delete-file $file)
  (system $cmd))
 (else
  (delete-file $file)))
;                                                                                    
(exit)

In above srcipt I load mystirng.scm. I show mystring.scm below. This script (function) find string pattern in given string (target string) .
Return value of this function is not boolean. So the name of this function is string-contains (not string-contains?). The return value is pointer number in target string if searching string pattern is founeded.


;                                                                                    
(define call/cc call-with-current-continuation)
;                                                                                    
(define (string-contains str1 str2)
  (define (string-str str1 str2 p)
    (call/cc (lambda (return1)
               (define n2 (string-length str2))
               (do
                   ((t p (+ t 1))
                    (u 0 (+ u 1)))
                   ((= t (+ p n2)) #t)
                 (if (not (char=? (string-ref str1 t) (string-ref str2 u)))
                     (return1 #f))))))
;                                                                                    
  (call/cc (lambda (return)
             (define n1 (string-length str1))
             (define n2 (string-length str2))
             (if (> n2 n1) (return #f))
             (do
                 ((p 0 (+ p 1)))
                 ((= p (+ 1 (- n1 n2))) #f)
       (if (string-str str1 str2 p)
                   (return p))))))
;                                                                                    




8. Router changed to BL900HW (NEC)

I changed my house in April, 2013. So internet-line changed. Router is also changed. Of course provider is changed.
This time I have to use BL-900HW (NEC router).
I show script for this router below.

#!/usr/bin/perl -w
# for Value-domain & NEC BL900HW (au)
#########################################################################


# get IP address from BL900HW
####################################
$workdir = "/var/ddns";                           # change work-directory to /var/ddns
$wgetpath = "/usr/local/bin/wget";                # your wget path

$userid   = "***";                                # your router user-id
$passwd = "*******";                              # your router password
$rtip     = "http://192.168.10.1/index.cgi/info_main"; # your router IP address & web-page
$file = "./tmp-log";

chdir $workdir || die;

if(-e $file){
    unlink $file || die;
}

!system ("$wgetpath -q -O $file --http-user=$userid --http-passwd=$passwd $rtip") || die;

open DATA, $file || die;
$iter = 0;
while(defined ($str = <DATA>)){
    if($str =~ /<td class=\'small_item_td2\'/){
        ++ $iter;
        if($iter == 28){
            last;
        }
    }
}
$str =~ s/<td class=\'small_item_td2\'>//;
$str =~ s/<\/td>//;
@line = split(/\//, $str);
$str = $line[0];

close DATA || die;

unlink $file;                    # to use seek & truncate is smarter style.
open DATA, ">".$file || die;
print DATA $str;
close DATA || die;


################################################
# compare both ip
# and update ddns_webpage if IP-address changed
################################################

$ipfile = "./ip-file";
$dm = "**********";              # your domainname
$pw = "**********";              # your ddns provider password

if(system("diff $ipfile $file >/dev/null 2>&1")){
    unlink $ipfile;
    rename $file, $ipfile;
    update_web ();
}else{
    unlink $file;
    if($ARGV[0] && ($ARGV[0] =~ /-f/i)){
        update_web ();
    }
}

########################################
# update provider web page sub program
# for value-domain ddns
########################################

sub update_web {
    open DATA, $ipfile || die;
    $ip = <DATA>;
    system "$wgetpath -q -O log 'http://dyn.value-domain.com/cgi-bin/dyn.fcg?d=$dm&p=$pw&h=*&i=$ip'";
    close DATA || die;
}






9. Same script (program) written in Scheme.

(This section, first edition in 2014, updated in Sep 2016.)

Next I show same script written in scheme. I use guile 2.0.x and Slackware (Sep 2016).
Guile 2.0.x is a little different from guile 1.8.x.
2.0.x is arrulity. It says "Oh I compile this script" or "Oh, this script is newer than I compiled before, so I compile it agein!"
When I use 2.0.x, arrulity is not bad. But! when I use 2.0.x in daemon mode ie backgraoud job, arrulity is not good.
All these things that 2.0.x saids will be delivered by E-mail to system administrator.
So, if I use guile 2.0.x as a background job (daemon mode), I have to do below.

First I show crontabs below.

5       *       *       *       *       /usr/bin/guile /var/ddns/ddns-tool 2 > /dev/null
3       5       5       *       *       /usr/bin/guile /var/ddns/ddns-tool -f 2 > /dev/null

This time I use not script, but guile command. So I put this (scheme program below) into /var/ddns. Because this file is not mode 755. Mode is 644.
I put above crontabs file into /var/spool/cron/crontabs directory. The name of file is "daemon2".
Then OS (slackware 14.2) runs this crontabs by the name of daemon2. (daemon2 privilege)
You see 2 > /dev/null. So arrulity comments from guile 2.0.x are dropped into /dev/null. OK.
And I set mail aliases file like this

daemon2: /dev/null

So if mail comes to daemon2, it will be dropped into /dev/null.Damon2 is just only for ddns-tool. So I can drop mails to daemon2. No problem at all.

;
; 2016.8.20 version for guile 2.0
;
(define (move-file a b) (copy-file a b) (delete-file a))
(define (cmd-arg) (cdr (command-line))) ; for argv
(use-modules (ice-9 rdelim)) ; for read-line
;
(define $workdir "/var/ddns")
(define $file    "tmp-file")
(define $passwd  "**********")
(define $usrid   "adm")
(define $rtip    "http://192.168.x.y/index.cgi/info_main.html")
(define $wgetpass "/usr/bin/wget")
;
(chdir $workdir)
;
(if (file-exists? $file)
    (delete-file $file) '())
;
(system (string-append $wgetpass " -q -O " $file " --http-user=" $usrid " --http-passwd=" $passwd " " $rtip))
;
; ---------------- extract
;
(define in-port (open-input-file $file))
(define $str1 "<td class='small_item_td2'>")
(define n1 (string-length $str1))
;
(define ans "")
(call/cc (lambda (return1)
             (do
               (($word (read-line in-port) (read-line in-port))
                (n 0))
              ((eof-object? $word) (exit))
             (if (and (string? $word) (string-contains $word $str1)) (set! n (+ n 1)) '())
             (if (>= n 28) (begin (set! ans $word)(return1 0)) '()))))
(close-input-port in-port)
;
(define s2 (substring ans n1 (string-length ans)))
(define p (string-contains s2 "/"))
(define s3 (substring s2 0 p))
;
(delete-file $file)
(define out-port (open-output-file $file))
(display s3 out-port)
(close-output-port out-port)
;
;--------------- copy from old file ------ update ----------
;
(define $pw "**********")
(define $dm "quinos.net")
(define $cmd (string-append "/usr/bin/wget -q -O log 'http://dyn.value-domain.com/cgi-bin/dyn.fcg?d=" $dm "&p=" $pw "&h=*&i=" s3 "'"))

(define $ip-file "ip-file")
(define ip-port (open-input-file $ip-file))
(define $ip (read-line ip-port))
(close-input-port ip-port)
;
(cond
 ((or (eof-object? $ip) (not (string=? $ip s3)))
  (delete-file $ip-file)
  (move-file $file $ip-file)
  (system $cmd))
 ((and (not (null? (cmd-arg))) (string=? (car (cmd-arg)) "-f"))
  (delete-file $file)
  (system $cmd))
 (else
  (delete-file $file)))
;
(exit)
;






10. dynamicDNS tool of NVR500 (YAMAHA router)

10-1. Lua program

Now, I show Lua program that works in NVR500 (YAMAHA router). I assume that access method is PPPoE.

Recently I have started to use Lua (programing language).
I have tried several computer languages. Such as, Fortran, Basic, C, C++, Scheme, Perl. Next is Lua.
About all these languages, I have not mastered. I learned just a little. (^^;;
Today, CPU is very fast. The technology of making interpreter is very heigh level. So, the languages that runs in interpreter style are very fast. Many Lispers and Schemers says this.
Indeed, I like to use Scheme. Sometimes Perl. I can't go back to C and shell script. It is hard for me to use these languages.

Main subject. Explaning Lua program that runs in NVR500. I show the list and explanation below.

May, 2017
I changed script to use filter for IP-spoofing. The filter that reject packet with wrong IP-address. This means that if the origin is my domain address, this is wrong packet. This must be from bad cracker.
Normary we use script file (that decides filter rules) to use IP-spoofing filter. But in case of DDNS, address changes dynamically. So we can't use script file.
By using lua with NVR500, it is quite easy. I show list below.

--
function getip ( )----------------------------------------------- function that gets IP address from nvr500 router
  local s, s1, s2, i
--
  i, s = rt.command("show status pp 1")-------------------------- show status pp 1 command gives us IP address
  i, s1 = string.find(s, "IP Address Local: ")------------------- this strings are just front of IP address
  s1 = s1 + 1
  s2 = s1 + 23
  s = string.sub (s, s1, s2);
  s2 = string.find(s, ", Remote:")------------------------------- this strings are just behind IP address
  s2 = s2 - 1
  s = string.sub(s, 1, s2)--------------------------------------- this is just IP address
  return s------------------------------------------------------- return IP address
end
---
function ipcmp( ip0, fl )---------------------------------------- this function compares 2 IP address, 1 from argument. 1 from file.
  local fp, ip
  fp = io.open (fl);
  ip = fp:read ("*l");------------------------------------------- read IP address from file
  io.close (fp);
---
  if ip0 == ip then
    return true;------------------------------------------------- if 2 addresses are same , then return true
  else
    fp = io.open(fl, "w")
    fp:write( ip0 )---------------------------------------------- if not same, write new IP address to the file
    io.close(fp)
    return false;------------------------------------------------ and return false.
  end
end
---
function update_web (ip) ---------------------------------------- DDNS site update function
  url_val = "http://dyn.value-domain.com/cgi-bin/dyn.fcg?d=%s&p=%s&h=*&i=%s";
  dm = "*********";
  pw = "*********";
  tbl_rq = {url = "", method = "GET", save_file = "usb1:/data/log"};
  tbl_rq.url = string.format (url_val, dm, pw, ip);
---
  rt.httprequest (tbl_rq);--------------------------------------- this is update
end
---
function ipfilter(ip) ------------------------------------------- function to use ip-filter that rejects IP-spoofing. (May, 2017)
    local cmd;
    cmd = string.format("ip filter 200004 reject %s/32 * * * *", ip) ----- set IP address by argument
    rt.command("pp select 1")
    rt.command(cmd) --------------------------------------------- decide filter rule
    rt.command("pp select none")
    rt.command("save") ------------------------------------------ save it
end
---
--- main program------------------------------------------------- small main program
---
local fl, ip
if #arg == 0 then
  fl = "usb1:/data/ipfile";
else
  fl  = arg[1];
end
---
ip = getip()
if ipcmp(ip, fl) == false then----------------------------------- compare 2 IP address
  update_web (ip);----------------------------------------------- if different, then update!
  ipfilter (ip); ------------------------------------------------ set filter rule for reject IP-spoofing
end


Now these 2 points, important!
*In Lua 5.1 and Lua 5.2, file:read("*l") is read 1 line. But in Lua 5.3,file:read("l") is read 1 line. Different.
*rt.httprequest (command in NVR500) not support https. It works just http.
This is tar-ball of the program. This tar-ball contains above program itself, someother programs and readme.

Nov 7, 2017
Now, Lua in NVR510 and NVR700W support https. But another router does not support https.
Please see here. http://www.rtpro.yamaha.co.jp/RT/docs/lua/#version
(Sorry in japanese)
Perhaps, soon or later, others support https. I hope !




10-2. How to use

This section shows how to use ddns-tool for YAMAHA router.

NVR500 has RTFS file-system in it. It is / file-system.

# show  file  list  /  all

Above shows what file is in / file system. Like "ls -l" in UNIX. If you don't install something to / , of course it is empty.
We can use 2 USB memories and 1 SD memory in NVR500. In order to use these memories, it is necessary to setup router. Please see NVR500 command reference.
In this section, I use USB slot 1. You should install files like below.

usb1:image

Of course we can use / file system. But accoding to YAMAHA's explanation, it is not recommended to use / with frequent writing access. It should break flash memory /. Flash memory is not tough to frequent writing access. Of course you know this.


It is necesary to use USB memory with FAT32 or FAT16 format. First, I tried NTFS formated USB memory. But I failed. So FAT32 or FAT16 is mandatry.
Extract tar-file, then you can see ddns-tool.lua, init.lua, cat.lua and some another files. Install files into USB like above picture directory constarction.
mydns.lua is for mydns.jp. But I'm not a member of mydns.jp. So I can not try weather it goes well or not. Sorry.

Each programs are

After install these programs into USB memory, put it into NVR500 and type below.

# lua usb1:/bin/cat.lua usb1:/bin/init.lua

Can you see init.lua source code ? Does cat.lua work well ? Ok it works. Next try ddns-tool.lua

# lua usb1:/bin/ddns-tool.lua

If it works well, 2 files have created in USB1:/data directory. These are ipfile and log. Let's see log by using cat.lua.

status=0
OK

If you can see above, ok, it works!
By using cat.lua, you can see ipfile. This file shows your IP address.
You want to try again ? If you type just like above again, ddns-tool.lua get your IP address again. But IP address got by script and ipfile are same. So ddns-tool.lua does not update website.
If you want to update again, type below.

# lua usb1:/bin/init.lua

This makes ipfile to empty file. So ddns-tool.lua goes to website and update again.

OK. Practice is over. Now we can use sceduler in NVR500. (scedule command).
The plan is below.

Init.lua,,, once a month. It is enough for value-domain. But accoding to mydns.jp website, one must update data at least once a week. So, init.lua should be done once a day, may be.
If you think you understand, please look at NVR500 manual to use scheduler.

I show my schedule below. I'm a member of value-domain. I use ddns-tool.lua once an hour. I use init.lua once a month.

schedule at 10 */* *:05 * lua usb1:/bin/ddns-tool.lua
schedule at 11 */3 3:03 * lua usb1:/bin/init.lua

First line. ddns-tool.lua runs 5 minutes past every hour.
Second line. Init.lua runs the 3rd day of every month. 3 miutes past 3 am.

I think NVR500 is useful and worth using. (^^)