Community discussions

 
draguzet
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 74
Joined: Fri Jul 01, 2011 10:28 am

Dyndns.org script, now to remove all log info ?

Tue Jan 31, 2012 2:09 am

I use this script, and set # on all log info's, but this is always on log
***
fetch:file "dyndns.checkip.html" crated
UpdateDynDns: No dyndns pdate needed
***

Is no need to be on log, and i would like to remove completely log about dyndns, only successfully change may appear on log. How to change script for this ?

# Set needed variables
:local username "user"
:local password "pass"
:local hostname "test.dyndns.org"

:global dyndnsForce
:global previousIP

# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" 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 currentIP [:pick $result $startLoc $endLoc]
:log info "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
:set dyndnsForce false
:set previousIP $currentIP
:log info "$currentIP or $previousIP"
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" \
dst-path="/dyndns.txt"
:local result [/file get dyndns.txt contents]
:log info ("UpdateDynDNS: Dyndns update needed")
:log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
:put ("Dyndns Update Result: ".$result)
} else={
:log info ("UpdateDynDNS: No dyndns update needed")
}
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Dyndns.org script, now to remove all log info ?

Tue Jan 31, 2012 1:04 pm

prefix all the lines you do not want to be executed with the "#" symbol. for example

turn
log info ("UpdateDynDNS: hostname = $hostname")
into
#log info ("UpdateDynDNS: hostname = $hostname")
 
draguzet
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 74
Joined: Fri Jul 01, 2011 10:28 am

Re: Dyndns.org script, now to remove all log info ?

Tue Jan 31, 2012 1:34 pm

I know it I use this script, and set # on all log info's, but this is always on log
***
fetch:file "dyndns.checkip.html" crated
UpdateDynDns: No dyndns pdate needed
***

Here is modified script:

# Set needed variables
:local username "user"
:local password "pass"
:local hostname "xxx.dyndns.tv"

:global dyndnsForce
:global previousIP

# print some debug info
#:log info ("UpdateDynDNS: username = $username")
#:log info ("UpdateDynDNS: password = $password")
#:log info ("UpdateDynDNS: hostname = $hostname")
#:log info ("UpdateDynDNS: previousIP = $previousIP")

# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" 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 currentIP [:pick $result $startLoc $endLoc]
#:log info "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
:set dyndnsForce false
:set previousIP $currentIP
:log info "$currentIP or $previousIP"
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" \
dst-path="/dyndns.txt"
:local result [/file get dyndns.txt contents]
:log info ("UpdateDynDNS: Dyndns update needed")
:log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
:put ("Dyndns Update Result: ".$result)
} else={
:log info ("UpdateDynDNS: No dyndns update needed")
}
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Dyndns.org script, now to remove all log info ?

Tue Jan 31, 2012 1:54 pm

you still have :log commands uncommented
 
draguzet
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 74
Joined: Fri Jul 01, 2011 10:28 am

Re: Dyndns.org script, now to remove all log info ?

Tue Jan 31, 2012 2:25 pm

Ok, now is all log commands commented, but one line in log are generated :(

Is any chance to remove except that disable "info loging" in settings ?
You do not have the required permissions to view the files attached to this post.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 24268
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: Dyndns.org script, now to remove all log info ?

Tue Jan 31, 2012 2:27 pm

why run the script so often? run it less often
No answer to your question? How to write posts
 
draguzet
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 74
Joined: Fri Jul 01, 2011 10:28 am

Re: Dyndns.org script, now to remove all log info ?

Tue Jan 31, 2012 2:34 pm

why run the script so often? run it less often
This is ADSL, reconnecting are possible in any time, and on this line are PPTP VPN for bussiness work and if connection are re-eastablished in working time I need smallest time to reconnect VPN again :(
But this is not subject of question, I can set every 5 min, again in all day I have log with many many unnecessary info about creating file :(
 
troy
Member
Member
Posts: 302
Joined: Thu Jun 30, 2005 6:47 pm

Re: Dyndns.org script, now to remove all log info ?

Tue Jan 31, 2012 3:22 pm

Run it every 5 seconds, 5 minutes, or 5 hours... don't fetch unless the IP has changed.

Here's the script I use and run every 5 minutes. The current IP is stored and used to compare next time the script is run.
:global currentIP;

:local tmpIP [/ip address get [find interface="WAN"] address];
:local myIP [:pick $tmpIP 0 [:find $tmpIP "/"]];

:if ($myIP != $currentIP) do={
    :log info "WAN IP address changed from $currentIP to $myIP"
    :foreach rule in=[/ip firewall nat find dst-address=$currentIP] do={
        /ip firewall nat set $rule dst-address=$myIP;
    }
    :set currentIP $myIP;
    /tool fetch url="http://url.to.server/page?args&stuff"
}
Last edited by troy on Wed Sep 12, 2012 6:11 pm, edited 1 time in total.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 24268
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: Dyndns.org script, now to remove all log info ?

Tue Jan 31, 2012 3:25 pm

good advice!
No answer to your question? How to write posts
 
draguzet
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 74
Joined: Fri Jul 01, 2011 10:28 am

Re: Dyndns.org script, now to remove all log info ?

Wed Feb 15, 2012 12:56 am

Any other advice for script improvement to save/compare current IP address without creating html file ?

Run it every 5 seconds, 5 minutes, or 5 hours... don't fetch unless the IP has changed.

Here's the script I use and run every 5 minutes. The current IP is stored and used to compare next time the script is run.
:global currentIP;

:local tmpIP [/ip address get [find interface="WAN"] address];
:local myIP [:pick $tmpIP 0 [:find $tmpIP "/"]];

:if ($myIP != $currentIP) do={
    :log info "WAN IP address changed from $currentIP to $myIP"
    :set currentIP $myIP;
    :foreach rule in=[/ip firewall nat find dst-address=$currentIP] do={
        /ip firewall nat set $rule dst-address=$myIP;
    }
    /tool fetch url="http://url.to.server/page?args&stuff"
}
 
troy
Member
Member
Posts: 302
Joined: Thu Jun 30, 2005 6:47 pm

Re: Dyndns.org script, now to remove all log info ?

Wed Feb 15, 2012 4:38 pm

My IP is pretty stable, so that html file only gets re-written a few times a year. It's annoying to see it, but not a huge issue for me.

Try something like this in the script to remove it:
/file remove [/file find name~"update.php.*"]
That's a very simple match, adjust the regex to suit your needs.
 
User avatar
robyhr
just joined
Posts: 16
Joined: Fri May 25, 2007 8:03 pm
Location: Croatia
Contact:

Re: Dyndns.org script, now to remove all log info ?

Wed Aug 22, 2012 2:29 am

i think you didnt understand original poster correctly - he removed all ":log" commands, but command "/tool fetch" produces log entry that cant be removed. so log still gets filled with those "fetch: file temp.txt created" messages.

however, i have 2 questions:

1. does doing "/tool fetch" every 5 minutes and then writing file to flash drive of RouterBoard decrease drive's lifetime, since it is not recommended to write to flash memories often?
2. is there any way to get your public IP (when youre behind NAT, and cant just read it from interface) without fetching it to file first, like fetching it directly into variable?

thank you very much for your time
 
troy
Member
Member
Posts: 302
Joined: Thu Jun 30, 2005 6:47 pm

Re: Dyndns.org script, now to remove all log info ?

Thu Aug 23, 2012 4:28 pm

i think you didnt understand original poster correctly - he removed all ":log" commands, but command "/tool fetch" produces log entry that cant be removed. so log still gets filled with those "fetch: file temp.txt created" messages.
Preventing the fetch from creating a log entry would be something that needs to be changed in the source. I don't think there's anything you can do in the script to prevent it.
however, i have 2 questions:

1. does doing "/tool fetch" every 5 minutes and then writing file to flash drive of RouterBoard decrease drive's lifetime, since it is not recommended to write to flash memories often?
In theory yes. If you choose to fetch every 5 minutes, you're going to see ~108k writes per year. Over time, the capacity of the flash drive will be reduced. If you want your router to last more than a few decades, you might want to avoid fetching/writing every 5 minutes.
2. is there any way to get your public IP (when youre behind NAT, and cant just read it from interface) without fetching it to file first, like fetching it directly into variable?

thank you very much for your time
Are you talking about a double-nat situation? If that's the case, knowing your outside address won't get you very far unless you control that router too, in which case, you can just read the IP from the interface.
 
User avatar
robyhr
just joined
Posts: 16
Joined: Fri May 25, 2007 8:03 pm
Location: Croatia
Contact:

Re: Dyndns.org script, now to remove all log info ?

Thu Aug 23, 2012 5:36 pm

... Are you talking about a double-nat situation? If that's the case, knowing your outside address won't get you very far unless you control that router too, in which case, you can just read the IP from the interface.
Thank you very much for answering my questions, troy.

About the last question, I have Siemens SX763 that does PPPoE and gets public IP. Siemens has NAT turned on, and is on local IP 192.168.1.1.
My Mikrotik is on 192.168.1.254 and does another NAT for my network 10.80.0.0/16.

Since there is no way Mikrotik can query Siemens for public IP, is fetch from web only way to get it?

thank you again :)
 
troy
Member
Member
Posts: 302
Joined: Thu Jun 30, 2005 6:47 pm

Re: Dyndns.org script, now to remove all log info ?

Mon Aug 27, 2012 5:12 pm

As far as I know, yes. A query to an outside server would be about the only way to do it.

Does the Siemens not have support for dynamic DNS?

Have you considered using OpenWRT on it? With this, you can have a shell and write any sort of script you want to do anything you need.
 
thiagomedeiros
just joined
Posts: 16
Joined: Tue Apr 03, 2012 10:38 pm

Re: Dyndns.org script, now to remove all log info ?

Sat Jul 30, 2016 7:58 pm

Hi all, first of all sorry for my bad english, I'm Brazilian.

So, reading the DNS-O-Matic API - (https://dnsomatic.com/wiki/api) - Documentation says: For clients using OpenDNS, a DNS request for myip.opendns.com will always return the public IP of the client.

And I tried:
:global currentIP [:resolve myip.opendns.com server=208.67.222.222];
Worked great! No more logs with fetch file...

Work for NAT too!


Here all the scheduler only script:
# DNSoMatic automatic DNS updates
#--------------- Change Values in this section to match your setup ------------------
# User account info of DNSoMatic

:local maticuser youruser
:local maticpass yourpassword

# Set the hostname or label of network to be updated. This is the part after the double colon (::) on the DNSoMatic services page.
# Hostnames with spaces are unsupported. Replace the value in the quotations below with your host names.
# To specify multiple hosts, separate them with commas. 
# Use "all.dnsomatic.com" for the matichost to update all items in dnsomatic with this IP.

:local matichost all.dnsomatic.com

#------------------------------------------------------------------------------------
# No more changes need

#OLD - Removing msg at log... fetch file...
#:global previousIP;
# Get the current public IP using DNS-O-Matic service.
#/tool fetch url="http://myip.dnsomatic.com/" mode=http dst-path=mypublicip.txt
# Read the current public IP into the currentIP variable.
#:local currentIP [/file get mypublicip.txt contents]

#NEW
:global previousIP;
:global currentIP [:resolve myip.opendns.com server=208.67.222.222];

:if ($currentIP != $previousIP) do={
    :log info "DNSoMatic: Update needed"
    :set previousIP $currentIP
    
# The update URL. Note the "\3F" is hex for question mark (?). Required since ? is a special character in commands.
    :local url "http://updates.dnsomatic.com/nic/update\3Fmyip=$currentIP&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
    :local matichostarray;
    :set matichostarray [:toarray $matichost];
    :foreach host in=$matichostarray do={
        :log info "DNSoMatic: Sending update for $host"
        /tool fetch url=($url . "&hostname=$host") user=$maticuser password=$maticpass mode=http dst-path=("dnsomaticupdate-" . $host . ".txt")
        :log info "DNSoMatic: Host $host updated on DNSoMatic with IP $currentIP"
    }
}  else={}
This is only to remove fetch file at log, if you would like no log at all, remove all :log comment's at code.

If I helped, rate positive for me. Thanks!
 
efaden
Forum Guru
Forum Guru
Posts: 1711
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: Dyndns.org script, now to remove all log info ?

Sun Jul 31, 2016 12:44 pm

I'll have to update my scripts to do this..

Sent from my XT1575 using Tapatalk
 
RLithgo
newbie
Posts: 30
Joined: Mon Dec 12, 2016 12:21 am

Re: Dyndns.org script, now to remove all log info ?

Thu Jan 19, 2017 3:39 am

:global currentIP [:resolve myip.opendns.com server=208.67.222.222];
Worked great! No more logs with fetch file...

Work for NAT too!
This method of fetching the wan ip works great for me too, and i'm not using opendns. This is a far superior way of scripting the dyndns updates without writing to flash and parsing the output file, which was the method i originally found somewhere else. The simplicity of this is awesome!
 
rftnon
newbie
Posts: 29
Joined: Fri Feb 28, 2014 6:34 pm

Re: Dyndns.org script, now to remove all log info ?

Sun Feb 12, 2017 8:49 pm

Thanks ...
This is useful and good ...
 
dadoremix
Member Candidate
Member Candidate
Posts: 118
Joined: Sat May 14, 2011 11:31 am

Re: Dyndns.org script, now to remove all log info ?

Sat Feb 18, 2017 10:23 am

anyone have complete script for dyndns .. working.. and that is not write to nand?

Ok
I realized the above script, but I have a question ..
How to update if you have multiple hosts on the same account, and want to update via dnsOmatic ?

Who is online

Users browsing this forum: No registered users and 19 guests