(Grav GitSync) Automatic Commit from tanshu
This commit is contained in:
parent
0c87e878c5
commit
86bad3ed92
49
pages/07.mikrotik/docs.md
Normal file
49
pages/07.mikrotik/docs.md
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
---
|
||||||
|
title: mikrotik
|
||||||
|
---
|
||||||
|
|
||||||
|
1. Script for DDNS
|
||||||
|
|
||||||
|
Create the following script with name `TanDNS` and the following permissions `write, test, read, policy`
|
||||||
|
```
|
||||||
|
# Tanshu automatic DNS updates
|
||||||
|
|
||||||
|
# User account info
|
||||||
|
:local user "user"
|
||||||
|
:local pass "123456"
|
||||||
|
|
||||||
|
# Set the hostname or label of network to be updated.
|
||||||
|
:local host "home.tanshu.com"
|
||||||
|
|
||||||
|
# Change to the name of interface that gets the changing IP address
|
||||||
|
:local inetinterface "pppoe-out1"
|
||||||
|
|
||||||
|
#- No more changes need -------------------------------------------------------------
|
||||||
|
: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 "TanDNS: 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://bifrost.tanshu.com/update\3Fdomain=$host"
|
||||||
|
:log info "TanDNS: Sending update for $host"
|
||||||
|
/tool fetch url=$url user=$user password=$pass mode=http dst-path=("TanDNSupdate-" . $host . ".txt")
|
||||||
|
:log info "TanDNS: Host $host updated on TanDNS with IP $currentIP"
|
||||||
|
} else={
|
||||||
|
:log info "TanDNS: Previous IP $previousIP and current IP equal, no update need"
|
||||||
|
}
|
||||||
|
} else={
|
||||||
|
:log info "TanDNS: $inetinterface is not currently running, so therefore will not update."
|
||||||
|
}```
|
Loading…
Reference in New Issue
Block a user