Skip to content

Commit 6116a02

Browse files
committed
Added DisableDomainIPAddressCheck variable. Updated readme.
1 parent 82bdbfa commit 6116a02

File tree

2 files changed

+69
-26
lines changed

2 files changed

+69
-26
lines changed

MikroTikDDNSUpdater.rsc

+63-21
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!rsc by RouterOS
22
# MikroTikDDNSUpdater
3-
# Build: 7
3+
# Build: 8
44
#
55
# https://github.com/lolostt/MikrotikDDNSUpdater
6-
# Copyright (C) 2023 Sleeping Coconut https://sleepingcoconut.com
6+
# Copyright (C) 2024 Sleeping Coconut https://sleepingcoconut.com
77
#
88
#
99
# This script updates dynamic DNS service using current public IP.
@@ -38,6 +38,7 @@
3838
# Other options:
3939
:local VerboseMode false;
4040
:local RequestWait 5; # [seconds]
41+
:local DisableDomainIPAddressCheck false;
4142

4243
# --------------------------------------------------------------------------------------------------
4344
# Hardcoded variables ( DO NOT EDIT unless you want to edit a service )
@@ -84,10 +85,12 @@
8485
:log error "MikroTikDDNSUpdater: DNS service credentials not configured";
8586
:error "MikroTikDDNSUpdater: DNS service credentials not configured";
8687
};
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+
};
9194
};
9295
};
9396

@@ -170,6 +173,8 @@ $checkDefaults DomainName=$DomainName \
170173
MikroTikCloudHostName=$MikroTikCloudHostName;
171174

172175
# ----------
176+
# Stage 2: public IP
177+
173178
# Stage 2a: get public IP address
174179

175180
:set PublicIPServiceURLSelected ($PublicIPServiceURLs->"$PublicIPServiceMode");
@@ -195,28 +200,66 @@ $checkDefaults DomainName=$DomainName \
195200
};
196201

197202
# ----------
198-
# Stage 3a: get domain IP address
203+
# Stage 3: domain IP
199204

200-
:set currentDomainIPAddress [$getDomainIP url=$DomainName;]
205+
:if ( $DisableDomainIPAddressCheck = false ) do={
201206

202-
# Stage 3b: check domain IP address
207+
# Stage 3a: get domain IP address
203208

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+
};
210220
};
211221
};
212222

213223
# ----------
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+
};
215258

216-
:if ( $currentPublicIPAddress = $currentDomainIPAddress ) do={
217-
:log info "MikroTikDDNSUpdater: update not needed for $DomainName";
218259
} else {
219-
# Stage 4b: call API
260+
261+
# Stage 4b: call API
262+
220263
:set APIURLWithArgs (($DDNSServiceURLs->"$DDNSService") \
221264
. \
222265
"hostname=$DomainName&myip=$currentPublicIPAddress");
@@ -233,8 +276,7 @@ $checkDefaults DomainName=$DomainName \
233276
]
234277

235278
:if ( $APIResponse = 0 ) do={
236-
:log info "MikroTikDDNSUpdater: $DomainName updated from \
237-
$currentDomainIPAddress to $currentPublicIPAddress";
279+
:log info "MikroTikDDNSUpdater: $DomainName updated to $currentPublicIPAddress";
238280
} else {
239281
$endScript message="MikroTikDDNSUpdater: DDNS service API call failed";
240282
};

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This is a set of scripts. Each script updates specific dynamic DNS service using
66
## Getting Started
77
### Prerequisites
88
#### Hardware
9-
- Mikrotik device running RouterOS 6.49.7. RouterOS 7 compatibility is not tested yet.
9+
- Mikrotik device running RouterOS 6.49.7 and up or 7.14.3 and up. Other RouterOS versions may be compatible but have not been tested.
1010

1111
### Installing
1212
1. Download, clone or copy script on your local computer.
@@ -26,16 +26,17 @@ You can also run it from terminal:
2626
```
2727

2828
### Available options
29-
- **DDNSService** (integer) variable lets you select dynamic DNS service. Note that different services requires different types of credentials.
29+
- **DDNSService** (integer) variable allows you to select a dynamic DNS service. Note that different services require different types of credentials.
3030
1. Service 1: DNS-O-Matic. Requires DDNSUserName and DDNSUserPassword.
3131
2. Service 2: No-IP. Requires DDNSUserName and DDNSUserPassword.
32-
- **PublicIPServiceMode** (integer) variable lets you select method of determining current public IP address:
32+
- **PublicIPServiceMode** (integer) variable allows you to select the method for determining the current public IP address:
3333
1. Method 1 uses icanhazip.com service.
3434
2. Method 2 uses Amazon Web Services service.
3535
3. Method 3 uses DNS-O-Matic service.
3636
9. Method 9 uses Mikrotik Cloud service. Requires MikroTikCloudHostName.
37-
- **VerboseMode** variable (boolean) lets you activate verbose mode.
38-
- **RequestWait** variable (integer) lets you define HTTP requests wait time (in seconds). Raise if network is slow.
37+
- **VerboseMode** variable (boolean) allows you to enable verbose mode.
38+
- **RequestWait** variable (integer) allows you to define the wait time for HTTP requests (in seconds). Increase this value if the network is slow.
39+
- **DisableDomainIPAddressCheck** variable (boolean) allows you to disable the determination of the domain's current IP address. This is useful when the system is behind a Cloudflare proxy or a similar service.
3940

4041

4142
### Script behaviour

0 commit comments

Comments
 (0)