Indice   FAQ  
Iscriviti  Login
Indice RouterOS Wiki routerOSiTalia [GUIDE]

Script DynDns - Codice - Come eseguirlo

In questa sezione puoi trovare alcune guide su routerOS

Ti è stata utile questa guida?Dà il tuo giudizio

SI
7
88%
NO
0
Nessun voto
NON NE AVEVO BISOGNO
1
13%
 
Voti totali : 8

Script DynDns - Codice - Come eseguirlo

Messaggioda figheras » dom 11 ott 2009, 12:07

Questo codice applicato alla vostra routerboard ha la funzione, una volta eseguito, di associare un dominio di terzo livello all'IP dinamico che viene fornito dal vostro ISP
In parole povere gestisce automaticamente l'account dyndns senza l'ausilio di un software e di un server.


    Come procedere:

-Tramite linea di comandi in "New terminal" inserite il seguente codice (Molto piu semplicemente facendo copia e incolla su winbox system>script>aggiungi "+")


    system script add=dyndns-update source=# Set needed variables
    :local username "dyndnsUsername"
    :local password "dyndnsPassword"
    :local hostname "hostname.dyndns.org"

    :global dyndnsForce
    :global previousIP

    # print some debug info
    :log info ("dyndns-update: username = $username")
    :log info ("dyndns-update: password = $password")
    :log info ("dyndns-update: hostname = $hostname")
    :log info ("dyndns-update: 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 "dyndns-update: currentIP = $currentIP"

    # Determine if dyndns update is needed
    # more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html
    :if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
    :set dyndnsForce false
    :set previousIP $currentIP
    /tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
    :local result [/file get dyndns.txt contents]
    :log info ("dyndns-update: Dyndns update needed")
    :log info ("dyndns-update: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)
    } else={
    :log info ("dyndns-update: No dyndns update needed")
    }

Cambiate le variabili inserendo le vostre credenziali:

    :local username "dyndnsUsername"
    :local password "dyndnsPassword"
    :local hostname "hostname.dyndns.org"

Una volta eseguita questa procedura, apriamo "New terminal" e inseriamo queste linee di comando:

  1. :global dyndnsForce true
    /system script run dyndns-update (esegue lo script)
    _______________________________________________________________________________
  2. /system scheduler add comment="" disabled=no interval=15m name=dyndns-update on-event=\
    dyndns-update start-date=jan/01/1970 start-time=00:00:00
    /system scheduler add comment="" disabled=no interval=1d name=dyndns-force on-event=\
    dyndns-force start-date=jan/01/1970 start-time=02:00:00é

(Settiamo lo schedulers in modo da far aggiornare lo script ogni 15 minuti e dyndns-force ogni 24 ore)
Siamo tutti ignoranti. Ma non tutti ignoriamo le stesse cose! - Einstein -
Avatar utente
figheras
Staff rosIT
Staff rosIT
 
Messaggi: 1218
Iscritto il: sab 19 set 2009, 20:09
Uso routerOS dalla Versione: v2.9.x
Certificazioni Mikrotik: MTCNA, MTCRE, MTCWE
Altre certificazioni: Cisco CCNA, KalliopePBX
Preferred Training Centre: Grifonline

Re: Script DynDns - Codice - Come eseguirlo

Messaggioda figheras » lun 12 ott 2009, 20:56

Questo codice applicato alla vostra routerboard ha la funzione, una volta eseguito, di associare un dominio di terzo livello all'IP dinamico che viene fornito dal vostro ISP
In parole povere gestisce automaticamente l'account dyndns senza l'ausilio di un software e di un server.......etc...etc....


    Questo codice può essere applicato soltanto ad apparati con versioni "ros" (routerOS) 3.x affinchè funzioni correttamente
Siamo tutti ignoranti. Ma non tutti ignoriamo le stesse cose! - Einstein -
Avatar utente
figheras
Staff rosIT
Staff rosIT
 
Messaggi: 1218
Iscritto il: sab 19 set 2009, 20:09
Uso routerOS dalla Versione: v2.9.x
Certificazioni Mikrotik: MTCNA, MTCRE, MTCWE
Altre certificazioni: Cisco CCNA, KalliopePBX
Preferred Training Centre: Grifonline

Re: Script DynDns - Codice - Come eseguirlo

Messaggioda figheras » mar 18 ott 2011, 13:17

[SCRIPT AGGIORNATO]


Per versioni 4.X

# Set needed variables
:local username "YourUsername"
:local password "YourPassword"
:local hostname "nohostset"
:global systemname [/system identity get name]

:if ($systemname = "Site1" ) do= {
:set hostname "yourdomain1.dyndns.org"
}
:if ($systemname = "Site2" ) do= {
:set hostname "yourdomain2.dyndns.org"
}
:if ($systemname = "Site3" ) do= {
:set hostname "yourdomain3.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
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
src-path="/nic/update?hostname=$hostname&myip=$currentIP" 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")
}


Per versioni 5.x

# Set needed variables
:local username "davidsoundeffects"
:local password "tyler2468"
:local hostname "gordonnewport.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")
}
Siamo tutti ignoranti. Ma non tutti ignoriamo le stesse cose! - Einstein -
Avatar utente
figheras
Staff rosIT
Staff rosIT
 
Messaggi: 1218
Iscritto il: sab 19 set 2009, 20:09
Uso routerOS dalla Versione: v2.9.x
Certificazioni Mikrotik: MTCNA, MTCRE, MTCWE
Altre certificazioni: Cisco CCNA, KalliopePBX
Preferred Training Centre: Grifonline

Re: Script DynDns - Codice - Come eseguirlo

Messaggioda delrout » mer 18 lug 2012, 12:23

Buongiorno figheras che tu sappia esiste qualcosa di adattabile a www.dnsdynamic.org. Grazie
delrout
Mikrotik Curious User
Mikrotik Curious User
 
Messaggi: 2
Iscritto il: mer 16 nov 2011, 1:16

Re: Script DynDns - Codice - Come eseguirlo

Messaggioda newtiger80 » gio 5 set 2013, 17:12

@Figheras
ciao, riporto quì in maniera semplificata il mio problema.
Utilizzando rb 411U con modulo UMTS integrato e SIM dati per trasferimento video, riscontro il seguente problema:
utilizzando un qualsiasi sito di dyndns (ex. changeip.com) vengo inserito nella blacklist quando lo script va in run ma il mio l'ip non varia, quindi non ho perso la connessione. in effetti se leggo nelle righe delle regole di utilizzo trovo (anche il dyndns.com) la postilla dice che non devo inviare false richieste di ip e quindi quando io invio lo stesso ip mi blocca l'account. le richieste devono essere al massimo 1 ogni ora e quindi ho fatto la seguente regola (schedule): \system script run NOMESCRIPT; mettendo come tempo di funzionamento 1 ora. in questo modo non ho problemi con la blacklist del dyndns ma ho problemi se avviene la seguente azione:
i gestori di telefonia mobile tagliano la connessione (specialmente nelle ore serali) quando si effettua troppo traffico oppure si sta troppo connessi, quindi in poche parole la notte cade la connessione e se lo script aveva appena effettuato la richiesta, resto 1 ora senza video.
la mia richiesta è: posso fare uno script che legga se l'ip è cambiato e far avviare la richiesta allo script del dyndns? in questo modo potrei inviare le richieste solo se l'ip cambia e non in vano.
grazie

Giovanni
Avatar utente
newtiger80
Mikrotik-User 10° Liv
Mikrotik-User 10° Liv
 
Messaggi: 15
Iscritto il: ven 14 gen 2011, 2:09

Re: Script DynDns - Codice - Come eseguirlo

Messaggioda lupin » gio 5 set 2013, 22:27

Strano.
Prova questo script.. da me funziona perfettamente


Codice: Seleziona tutto
/system scheduler
add interval=1m name=dynDNS on-event=dynDNS policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-time=startup


/system script
add name=dynDNS policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source="# Set needed \
    variables\r\
    \n:local username \"tuouser\"\r\
    \n:local password \"tuapassword\"\r\
    \n:local hostname \"tuoname.dyndns.org\"\r\
    \n:global systemname [/system identity get name]\r\
    \n\r\
    \n:if (\$systemname  = \"Site1\" ) do= {\r\
    \n:set hostname \"yourdomain1.dyndns.org\"\r\
    \n}\r\
    \n:if (\$systemname  = \"Site2\" ) do= {\r\
    \n:set hostname \"yourdomain2.dyndns.org\"\r\
    \n}\r\
    \n:if (\$systemname  = \"Site3\" ) do= {\r\
    \n:set hostname \"yourdomain3.dyndns.org\"\r\
    \n}\r\
    \n\r\
    \n:global dyndnsForce\r\
    \n:global previousIP\r\
    \n\r\
    \n# print some debug info\r\
    \n:log info (\"UpdateDynDNS: username = \$username\")\r\
    \n:log info (\"UpdateDynDNS: password = \$password\")\r\
    \n:log info (\"UpdateDynDNS: hostname = \$hostname\")\r\
    \n:log info (\"UpdateDynDNS: previousIP = \$previousIP\")\r\
    \n\r\
    \n# get the current IP address from the internet (in case of double-nat)\r\
    \n/tool fetch mode=http address=\"checkip.dyndns.org\" src-path=\"/\" dst-path=\"/dyndns.checkip.html\"\r\
    \n:local result [/file get dyndns.checkip.html contents]\r\
    \n\r\
    \n# parse the current IP result\r\
    \n:local resultLen [:len \$result]\r\
    \n:local startLoc [:find \$result \": \" -1]\r\
    \n:set startLoc (\$startLoc + 2)\r\
    \n:local endLoc [:find \$result \"</body>\" -1]\r\
    \n:local currentIP [:pick \$result \$startLoc \$endLoc]\r\
    \n:log info \"UpdateDynDNS: currentIP = \$currentIP\"\r\
    \n\r\
    \n# Remove the # on next line to force an update every single time - useful for debugging,\r\
    \n#  but you could end up getting blacklisted by DynDNS!\r\
    \n\r\
    \n#:set dyndnsForce true\r\
    \n\r\
    \n# Determine if dyndns update is needed\r\
    \n# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html\r\
    \n:if ((\$currentIP != \$previousIP) || (\$dyndnsForce = true)) do={\r\
    \n    :set dyndnsForce false\r\
    \n    :set previousIP \$currentIP\r\
    \n    /tool fetch user=\$username password=\$password mode=http address=\"members.dyndns.org\" \\\r\
    \n       src-path=\"/nic/update\?hostname=\$hostname&myip=\$currentIP\" dst-path=\"/dyndns.txt\"\r\
    \n    :local result [/file get dyndns.txt contents]\r\
    \n    :log info (\"UpdateDynDNS: Dyndns update needed\")\r\
    \n    :log info (\"UpdateDynDNS: Dyndns Update Result: \".\$result)\r\
    \n    :put (\"Dyndns Update Result: \".\$result)\r\
    \n} else={\r\
    \n    :log info (\"UpdateDynDNS: No dyndns update needed\")\r\
    \n}\r\
    \n"
lupin
Mikrotik-User 10° Liv
Mikrotik-User 10° Liv
 
Messaggi: 17
Iscritto il: lun 26 apr 2010, 22:46

Re: Script DynDns - Codice - Come eseguirlo

Messaggioda newtiger80 » lun 9 set 2013, 9:23

ciao, lo testo e ti faccio sapere... grazie
Avatar utente
newtiger80
Mikrotik-User 10° Liv
Mikrotik-User 10° Liv
 
Messaggi: 15
Iscritto il: ven 14 gen 2011, 2:09

Re: Script DynDns - Codice - Come eseguirlo

Messaggioda newtiger80 » lun 23 set 2013, 14:23

ciao a tutti, scusate per l'assenza ma tra il lavoro e le ferie non mi sono connesso. lo script va benissimo, ma a me servirebbe uno script che, tramite una schedule, faccia ogni 5 minuti il controllo dell'interfaccia pppoclient (nel mio caso la sim operatore) se ha cambiato l'indirizzo dinamico. e se è stato sostituito far fare un run allo script del dyndns...
spero di essere stato chiaro...

grazie
Avatar utente
newtiger80
Mikrotik-User 10° Liv
Mikrotik-User 10° Liv
 
Messaggi: 15
Iscritto il: ven 14 gen 2011, 2:09

Re: Script DynDns - Codice - Come eseguirlo

Messaggioda figheras » mar 24 set 2013, 7:59

Basta schedulare lo script in modo che lo esegua ad intervalli regolari....così anche se il client pppoe dovesse andare giù per poi riallinearsi nn hai problemi!
Siamo tutti ignoranti. Ma non tutti ignoriamo le stesse cose! - Einstein -
Avatar utente
figheras
Staff rosIT
Staff rosIT
 
Messaggi: 1218
Iscritto il: sab 19 set 2009, 20:09
Uso routerOS dalla Versione: v2.9.x
Certificazioni Mikrotik: MTCNA, MTCRE, MTCWE
Altre certificazioni: Cisco CCNA, KalliopePBX
Preferred Training Centre: Grifonline

Re: Script DynDns - Codice - Come eseguirlo

Messaggioda newtiger80 » mar 24 set 2013, 12:49

figheras ha scritto:Basta schedulare lo script in modo che lo esegua ad intervalli regolari....così anche se il client pppoe dovesse andare giù per poi riallinearsi nn hai problemi!


Ciao, torno al solito problema di changeIP ( un cliente ha la licenza non posso dire di cambiare) se invio anche solo 4 o 5 richieste di ip non variato mi blocca l'account per 24 ore... Ho già fatto un run script ogni ora per evitare i blocchi, ma rischio la perdita del video (poichè faccio videosorveglianza) se cambia ip entro l'ora. quindi mi servirebbe un controllo ip che se vede variazione mi va avviare lo script dyndns... tutto quì....
gli script funzionano tutti compreso quello che ho io.
ciao, grazie

[paura]
Avatar utente
newtiger80
Mikrotik-User 10° Liv
Mikrotik-User 10° Liv
 
Messaggi: 15
Iscritto il: ven 14 gen 2011, 2:09


Prossimo

Torna a Wiki routerOSiTalia [GUIDE]

Chi c’è in linea

Visitano il forum: Nessuno e 3 ospiti