Last active
November 17, 2024 00:35
-
-
Save ergolyam/939ed26ca786af787c0b9b89be2aea64 to your computer and use it in GitHub Desktop.
freedomain DynDNS for mikrotik
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
| # MikroTik Script: freedomain.rsc | |
| # Purpose: Update DNS records dynamically | |
| :local apiKey "api_key" | |
| :local domain "example.com,example.org" | |
| :local fileName "last_pppoe_ip.txt" | |
| :local lastIP | |
| :local currentIP | |
| :if ([/file find name=$fileName] = "") do={ | |
| /file print file=$fileName | |
| :log info "File $fileName created." | |
| } | |
| :if ([/file find name=$fileName] != "") do={ | |
| :set lastIP [/file get [/file find name=$fileName] contents] | |
| } | |
| # command to get ip from pppoe interface | |
| :set currentIP [/ip address get [find interface="pppoe-out1"] address] | |
| :if ($currentIP != $lastIP) do={ | |
| :local url "https://api.dnsexit.com/dns/ud/?apikey=$apiKey" | |
| /tool fetch url=$url http-method=post http-data="host=$domain" mode=https dst-path=/dev/null keep-result=no | |
| :file set [/file find name=$fileName] contents=$currentIP | |
| :log info "DNS record for $domain updated to $currentIP." | |
| } else={ | |
| :log info "No changes in IP address. Update not required." | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment