1
1
#!rsc by RouterOS
2
2
# MikroTikDDNSUpdater
3
- # Build: 7
3
+ # Build: 8
4
4
#
5
5
# https://github.com/lolostt/MikrotikDDNSUpdater
6
- # Copyright (C) 2023 Sleeping Coconut https://sleepingcoconut.com
6
+ # Copyright (C) 2024 Sleeping Coconut https://sleepingcoconut.com
7
7
#
8
8
#
9
9
# This script updates dynamic DNS service using current public IP.
38
38
# Other options:
39
39
:local VerboseMode false;
40
40
:local RequestWait 5; # [seconds]
41
+ :local DisableDomainIPAddressCheck false;
41
42
42
43
# --------------------------------------------------------------------------------------------------
43
44
# Hardcoded variables ( DO NOT EDIT unless you want to edit a service )
84
85
:log error "MikroTikDDNSUpdater: DNS service credentials not configured";
85
86
:error "MikroTikDDNSUpdater: DNS service credentials not configured";
86
87
};
87
- :if ( $PublicIPServiceMode = "9" && \
88
- $MikroTikCloudHostName = "SERIALNUMBER.sn.mynetname.net" ) do={
89
- :log error "MikroTikDDNSUpdater: MikroTikCloudHostName variable not configured";
90
- :error "MikroTikDDNSUpdater: MikroTikCloudHostName variable not configured";
88
+ :if ( $DisablePublicIPAddressCheck = false ) do={
89
+ :if ( $PublicIPServiceMode = "9" && \
90
+ $MikroTikCloudHostName = "SERIALNUMBER.sn.mynetname.net" ) do={
91
+ :log error "MikroTikDDNSUpdater: MikroTikCloudHostName variable not configured";
92
+ :error "MikroTikDDNSUpdater: MikroTikCloudHostName variable not configured";
93
+ };
91
94
};
92
95
};
93
96
@@ -170,6 +173,8 @@ $checkDefaults DomainName=$DomainName \
170
173
MikroTikCloudHostName=$MikroTikCloudHostName;
171
174
172
175
# ----------
176
+ # Stage 2: public IP
177
+
173
178
# Stage 2a: get public IP address
174
179
175
180
:set PublicIPServiceURLSelected ($PublicIPServiceURLs->"$PublicIPServiceMode");
@@ -195,28 +200,66 @@ $checkDefaults DomainName=$DomainName \
195
200
};
196
201
197
202
# ----------
198
- # Stage 3a: get domain IP address
203
+ # Stage 3: domain IP
199
204
200
- :set currentDomainIPAddress [$getDomainIP url=$DomainName;]
205
+ :if ( $DisableDomainIPAddressCheck = false ) do={
201
206
202
- # Stage 3b: check domain IP address
207
+ # Stage 3a: get domain IP address
203
208
204
- :if ( $currentDomainIPAddress = "0.0.0.0" || \
205
- $currentDomainIPAddress = nil ) do={
206
- $endScript message="MikroTikDDNSUpdater: domain IP address determination failed";
207
- } else {
208
- :if ( $VerboseMode = true ) do={
209
- :log info "MikroTikDDNSUpdater: domain IP address is $currentDomainIPAddress";
209
+ :set currentDomainIPAddress [$getDomainIP url=$DomainName;]
210
+
211
+ # Stage 3b: check domain IP address
212
+
213
+ :if ( $currentDomainIPAddress = "0.0.0.0" || \
214
+ $currentDomainIPAddress = nil ) do={
215
+ $endScript message="MikroTikDDNSUpdater: domain IP address determination failed";
216
+ } else {
217
+ :if ( $VerboseMode = true ) do={
218
+ :log info "MikroTikDDNSUpdater: domain IP address is $currentDomainIPAddress";
219
+ };
210
220
};
211
221
};
212
222
213
223
# ----------
214
- # Stage 4a: compare IP addresses
224
+ # Stage 4: IP addresses comparison and API call
225
+
226
+ :if ( $DisableDomainIPAddressCheck = false ) do={
227
+
228
+ # Stage 4a: compare IP addresses
229
+
230
+ :if ( $currentPublicIPAddress = $currentDomainIPAddress ) do={
231
+ :log info "MikroTikDDNSUpdater: update not needed for $DomainName";
232
+ } else {
233
+
234
+ # Stage 4b: call API
235
+
236
+ :set APIURLWithArgs (($DDNSServiceURLs->"$DDNSService") \
237
+ . \
238
+ "hostname=$DomainName&myip=$currentPublicIPAddress");
239
+
240
+ :if ( $VerboseMode = true ) do={
241
+ :log info "MikroTikDDNSUpdater: calling API with url: $APIURLWithArgs";
242
+ };
243
+
244
+ :set APIResponse [
245
+ $APICall url=$APIURLWithArgs \
246
+ userName=$DDNSUserName \
247
+ userPassword=$DDNSUserPassword \
248
+ requestWait=$RequestWaitConverted;
249
+ ]
250
+
251
+ :if ( $APIResponse = 0 ) do={
252
+ :log info "MikroTikDDNSUpdater: $DomainName updated from \
253
+ $currentDomainIPAddress to $currentPublicIPAddress";
254
+ } else {
255
+ $endScript message="MikroTikDDNSUpdater: DDNS service API call failed";
256
+ };
257
+ };
215
258
216
- :if ( $currentPublicIPAddress = $currentDomainIPAddress ) do={
217
- :log info "MikroTikDDNSUpdater: update not needed for $DomainName";
218
259
} else {
219
- # Stage 4b: call API
260
+
261
+ # Stage 4b: call API
262
+
220
263
:set APIURLWithArgs (($DDNSServiceURLs->"$DDNSService") \
221
264
. \
222
265
"hostname=$DomainName&myip=$currentPublicIPAddress");
@@ -233,8 +276,7 @@ $checkDefaults DomainName=$DomainName \
233
276
]
234
277
235
278
:if ( $APIResponse = 0 ) do={
236
- :log info "MikroTikDDNSUpdater: $DomainName updated from \
237
- $currentDomainIPAddress to $currentPublicIPAddress";
279
+ :log info "MikroTikDDNSUpdater: $DomainName updated to $currentPublicIPAddress";
238
280
} else {
239
281
$endScript message="MikroTikDDNSUpdater: DDNS service API call failed";
240
282
};
0 commit comments