Skip to content

Instantly share code, notes, and snippets.

@wannadrunk
Last active September 14, 2023 11:53
Show Gist options
  • Save wannadrunk/e1438628b88c2fcae6c006ff067efae7 to your computer and use it in GitHub Desktop.
Save wannadrunk/e1438628b88c2fcae6c006ff067efae7 to your computer and use it in GitHub Desktop.

Revisions

  1. wannadrunk renamed this gist Sep 14, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. wannadrunk created this gist Sep 14, 2023.
    35 changes: 35 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    # 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"