View difference between Paste ID: 7H1M8nkn and TLs3tpEM
SHOW: | | - or go back to the newest paste.
1
# No-IP automatic Dynamic DNS update
2
3
# Michael Martins - 2019 
4
# O Script faz o envio das informações para a sua conta No-IP
5
# Após inserir o Script no Mikrotik, Criar um Scheduler para executar o Script de acordo com sua necessidade.
6
7
#--------------- Modifique os valores nessa área de acordo com suas configurações ------------------
8
9
# SUAS INFORMAÇÕES DA CONTA NO-IP  EMAIL E SENHA
10
:local noipuser "XXXXXXX@hotmail.com"
11
:local noippass "XXXXXXX"
12
13
# HOSTNAME QUE SERÁ ATUALIZADO
14
15
# Hostnames with spaces are unsupported. Replace the value in the quotations below with your host names.
16
17
# PARA ESPECIFICAR VÁRIOS HOSTS, SEPARAR POR VÍRGULA.
18
:local noiphost "sunshinenetwork.ddns.net"
19
20
# MODIFIQUE ABAIXO A INTERFACE E COLOQUE A QUE RECEBE O IP DINÂMICO DA OPERADORA
21
# Change to the name of interface that gets the dynamic IP address
22
:local inetinterface "pppoe-out1"
23
24
#------------------------------------------------------------------------------------
25
# NÃO É NECESSÁRIO FAZER NENHUMA ALTERAÇÃO ABAIXO
26
27
:global previousIP
28
29
:if ([/interface get $inetinterface value-name=running]) do={
30
# Get the current IP on the interface
31
   :local currentIP [/ip address get [find interface="$inetinterface" disabled=no] address]
32
33
# Strip the net mask off the IP address
34
   :for i from=( [:len $currentIP] - 1) to=0 do={
35
       :if ( [:pick $currentIP $i] = "/") do={ 
36
           :set currentIP [:pick $currentIP 0 $i]
37
       } 
38
   }
39
40
   :if ($currentIP != $previousIP) do={
41
       :log info "No-IP: Current IP $currentIP is not equal to previous IP, update needed"
42
       :set previousIP $currentIP
43
44
# The update URL. Note the "\3F" is hex for question mark (?). Required since ? is a special character in commands.
45
       :local url "http://dynupdate.no-ip.com/nic/update\3Fmyip=$currentIP"
46
       :local noiphostarray
47
       :set noiphostarray [:toarray $noiphost]
48
       :foreach host in=$noiphostarray do={
49
           :log info "No-IP: Sending update for $host"
50
           /tool fetch url=($url . "&hostname=$host") user=$noipuser password=$noippass mode=http dst-path=("no-ip_ddns_update-" . $host . ".txt")
51
           :log info "No-IP: Host $host updated on No-IP with IP $currentIP"
52
       }
53
   }  else={
54
       :log info "No-IP: Previous IP $previousIP is equal to current IP, no update needed"
55
   }
56
} else={
57
   :log info "No-IP: $inetinterface is not currently running, so therefore will not update."
58
}