Indice   FAQ  
Iscriviti  Login
Indice RouterOS RouterOS

Problema con script per aggiornamento DDNS

Tutto su questo sistema operativo linux based - Configurazioni, dubbi, problematiche &....

Problema con script per aggiornamento DDNS

Messaggioda Jetro » mer 17 apr 2019, 12:16

Ciao a tutti, ho provato a cercare tra le discussioni ma non ho trovato nessuno con il mio problema. Ho degli Hostname su noIP ed uno di questi lo sto utilizzando su un router Mikrotik, aggiornandolo tramite uno script trovato in rete.

Il problema è nel caricamento dell'indirizzo IP precedente (che non avviene), di conseguenza ogni volta in cui viene lanciato l'IP mi fa un update sul server (solitamente non necessario).

A me sembra manchi proprio la parte di codice che dovrebbe caricare in memoria il valore dell'indirizzo IP precedente; qualcuno saprebbe aiutarmi a riguardo?

Di seguito il codice:

Codice: Seleziona tutto
:global previousIP

:if ([/interface get $inetinterface value-name=running]) do={
# Get the current IP on the interface
   :local currentIP [/ip address get [find interface="$inetinterface" disabled=no] address]

# Strip the net mask off the IP address
   :for i from=( [:len $currentIP] - 1) to=0 do={
       :if ( [:pick $currentIP $i] = "/") do={
           :set currentIP [:pick $currentIP 0 $i]
       }
   }

   :if ($currentIP != $previousIP) do={
       :log info "No-IP: Current IP $currentIP is not equal to previous IP $previousIP, 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://dynupdate.no-ip.com/nic/update\3Fmyip=$currentIP"
       :local noiphostarray
       :set noiphostarray [:toarray $noiphost]
       :foreach host in=$noiphostarray do={
           :log info "No-IP: Sending update for $host"
           /tool fetch url=($url . "&hostname=$host") user=$noipuser password=$noippass mode=http dst-path=("no-ip_ddns_update-" . $host . ".txt")
           :log info "No-IP: Host $host updated on No-IP with IP $currentIP"
       }
   }  else={
       :log info "No-IP: Previous IP $previousIP is equal to current IP, no update needed"
   }
} else={
   :log info "No-IP: $inetinterface is not currently running, so therefore will not update."
}


:thanks:
Jetro
Mikrotik Curious User
Mikrotik Curious User
 
Messaggi: 7
Iscritto il: mer 17 apr 2019, 12:06
Uso routerOS dalla Versione: v6.x

Re: Problema con script per aggiornamento DDNS

Messaggioda abbio90 » mar 23 apr 2019, 21:58

ciao, potresti semplificarti la vita utilizzando la funzione gratuita di mikrotik
IP CLOUD
Scopri https://foisfabio.it - Tutorial sul Network
Avatar utente
abbio90
Mikrotik-Pro 1° Liv
Mikrotik-Pro 1° Liv
 
Messaggi: 517
Iscritto il: lun 26 giu 2017, 19:11
Località: Oristano
Uso routerOS dalla Versione: v4.x
Certificazioni Mikrotik: MTCNA

Re: Problema con script per aggiornamento DDNS

Messaggioda Jetro » ven 26 apr 2019, 23:01

Non ne conoscevo l'esistenza, ottimo a sapersi!

Resta però l'interesse su come correggere lo script (che in ogni caso funziona, solo che fa molti aggiornamenti non necessari) :beer:
Jetro
Mikrotik Curious User
Mikrotik Curious User
 
Messaggi: 7
Iscritto il: mer 17 apr 2019, 12:06
Uso routerOS dalla Versione: v6.x



Torna a RouterOS

Chi c’è in linea

Visitano il forum: Nessuno e 2 ospiti