:if ([/interface get $WANIF value-name=running]) do={ # Get the current public IP :local requestip [/tool fetch url="http://ifconfig.io/ip" mode=http output=user as-value] :set IP4NEW [:pick ($requestip->"data") 0 ([:len ($requestip->"data")]-1)] # Check if IP has changed :if ($IP4NEW != $IP4CUR) do={ :log info "CF-DDNS: Public IP changed to $IP4NEW, updating" :local cfapi [/tool fetch http-method=put mode=https url=$url check-certificate=yes output=user as-value \ http-header-field="Authorization: Bearer $TOKEN,Content-Type: application/json" \ http-data="{\"type\":\"A\",\"name\":\"$RECORDNAME\",\"content\":\"$IP4NEW\",\"ttl\":1,\"proxied\":false}"] :set IP4CUR $IP4NEW :log info "CF-DDNS: Host $RECORDNAME updated with IP $IP4CUR" } else={ :log info "CF-DDNS: Previous IP $IP4NEW not changed, quitting" } } else={ :log info "CF-DDNS: $WANIF is not currently running, quitting" }