Last active
August 25, 2024 03:26
-
-
Save breakertt/d8b22f2a9aa06c4233cce96b6cc2944b to your computer and use it in GitHub Desktop.
Mikrotik script to update record for dynv6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # !!!!!!! Minimal Mikrotik Vesrion 7.14 !!!!!!!!! | |
| # | |
| # Get DNS zone id and record id | |
| # curl \ | |
| # -H "Authorization: Bearer {HTTP_TOKEN}" \ | |
| # -H "Accept: application/json" \ | |
| # https://dynv6.com/api/v2/zones | |
| # curl \ | |
| # -H "Authorization: Bearer {HTTP_TOKEN}" \ | |
| # -H "Accept: application/json" \ | |
| # https://dynv6.com/api/v2/zones/{zoneID}/records | |
| # --- config --- | |
| :local zoneid "{zoneID}" | |
| :local recordid "{recordID}" | |
| :local token "{HTTP_TOKEN}" | |
| :local recordname "{RECORD_NAME}" | |
| :local recorddomain "{RECORD_DOMAIN}" | |
| :local publicinterface "{PUBLIC_INTERFACE}" | |
| # --- config end --- | |
| :local ipddns [:resolve $recorddomain] | |
| :local ipfresh [ /ip address get [/ip address find interface=$publicinterface ] address ] | |
| :set ipfresh [:pick $ipfresh 0 [:find $ipfresh "/" -1]] | |
| :log info "dynv6 ddns local_ip $ipfresh ddns_ip $ipddns" | |
| :if ($ipddns != $ipfresh) do={ | |
| :local dynv6url "https://dynv6.com/api/v2/zones/$zoneid/records/$recordid" | |
| :local dynv6data "{\"name\":\"$recordname\",\"data\":\"$ipfresh\"}" | |
| :local dynv6header "Authorization: Bearer $token,Content-Type: application/json" | |
| :log info "dynv6 url $dynv6url data $dynv6data header $dynv6header" | |
| :local result [/tool fetch url=$dynv6url http-data=$dynv6data http-header-field=$dynv6header http-method=patch mode=https check-certificate=no as-value output=user] | |
| :local status ($result->"status"); | |
| :local data ($result->"data"); | |
| :log info "status $status data $data" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment