-
Notifications
You must be signed in to change notification settings - Fork 118
/
[Script-MikroTik] NO-IP.COM DDNS Update.txt
54 lines (44 loc) · 1.94 KB
/
[Script-MikroTik] NO-IP.COM DDNS Update.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# No-IP, Dynamic DNS Updater
# TechBlogClub by Krittin Srithong
#--------------- Change your information here ------------------
:local noipuser "enterNOIPUsername"
:local noippass "enterNOIPPassword"
:local noiphost "enterYOURhostname.ddns.net"
:local inetinterface "pppoe-out1"
#---------------------------------------------------------------
: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]
}
}
# 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={
# Check 1 - resolved IP
:local resolvedIP [:resolve $host];
# Check 2 - Saved response from NO-IP
:local filename ("no-ip_ddns_update-" . $host . ".txt")
:local savedMatch -1
:local savedIP "No File";
if ( [:len [/file find name=$filename]] > 0 ) do={
:set savedIP [/file get $filename contents]
:set savedMatch [:find $savedIP $currentIP -1]
}
# If either check fails, update IP
:if (($currentIP = $resolvedIP) && ($savedMatch >= 0)) do={
:log info "No-IP: Host $host already on No-IP with IP $resolvedIP"
} else={
:log info "No-IP: Sending update for $host - $resolvedIP saved as $savedIP"
/tool fetch url=($url . "&hostname=$host") user=$noipuser password=$noippass mode=http dst-path=$filename
:log info "No-IP: Host $host updated on No-IP with IP $currentIP"
}
}
} else={
:log info "No-IP: $inetinterface is not currently running, so therefore will not update."
}