Last active
September 14, 2023 11:53
-
-
Save wannadrunk/e1438628b88c2fcae6c006ff067efae7 to your computer and use it in GitHub Desktop.
MikroTik script to loop the pppoe connection until it get the public IP, not NAT IP. And then update the DNS A record on CloudFlare Name Server.
This file contains 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 for loop until get the public IP from NT | |
# and then set DNS A record to that public IP. | |
# | |
# Update WANIF to match your interface name. And all CloudFlare required key and info. | |
# | |
# Put this into the ppp profile UP script and assign to pppoe connection | |
# | |
:local WANIF "pppoe-1"; | |
:while ( $"local-address" in 100.64.0.0/10 ) do={ | |
:log warning ("$WANIF: Got Private IP ".$"local-address"." Reconnecting the interface..."); | |
/interface pppoe-client disable $WANIF; | |
:delay 10s; | |
/interface pppoe-client enable $WANIF; | |
}; | |
:log info ("$WANIF: Got IP ".$"local-address"); | |
:local IP4NEW $"local-address" | |
# Cloudflare Dynamic DNS update script | |
# Required policy: read, write, test, policy | |
# Configuration --------------------------------------------------------------------- | |
:local TOKEN "__TokenAPI__" | |
:local ZONEID "__ZoneID__" | |
:local RECORDID "__RecordID__" | |
:local RECORDNAME "__SubDomainName__" | |
#------------------------------------------------------------------------------------ | |
:local url "https://api.cloudflare.com/client/v4/zones/$ZONEID/dns_records/$RECORDID/" | |
:local cfapi [/tool fetch http-method=put mode=https url=$url check-certificate=no output=user as-value \ | |
http-header-field="Authorization: Bearer $TOKEN,Content-Type: application/json" \ | |
http-data="{\"type\":\"A\",\"name\":\"$RECORDNAME\",\"content\":\"$IP4NEW\",\"ttl\":120,\"proxied\":false}"] | |
:log info "CF-DDNS: Host $RECORDNAME updated with IP $IP4NEW" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment