14
Фев

Скрипт обновления ipv6 адреса доменного имени на Cloudflare для Mikrotik ROS 7

:global botToken
:global chatID

:local hostname "hd.zp.ua"
:local WANInterface "ISP1"
:local email "[email protected]"

:local CFtoken "3c8c58sdfsdfsdfsdfds6e8068177a33"
:local CFzoneid "824d6ce57sdfsdfsdfdsfdsf04ea9664"
:local CFrecordid "d1a4225sdfsdfdsfdsfdsfs86911f46112"

:log info "=== IPv6 DDNS (resolve) запущен ==="

# 1. Получаем PD и целевой IP
:local pd [/ipv6 dhcp-client get [find interface=$WANInterface] prefix]
:if ([:len $pd] = 0) do={ :log/error "Нет PD"; :error }

:local prefix [:pick $pd 0 [:find $pd "/"]]
:local targetIP ($prefix . "1")
:log info "Целевой IP: $targetIP"

# 2. Обновляем локальный адрес на WAN
:local currentIP ""
:local addrID [/ipv6 address find interface=$WANInterface global=yes advertise=no]
:if ([:len $addrID] > 0) do={
    :set currentIP [:pick [/ipv6 address get $addrID address] 0 [:find [/ipv6 address get $addrID address] "/"]]
}
:if ($currentIP != $targetIP) do={
    :if ([:len $addrID] > 0) do={ /ipv6 address remove $addrID }
    /ipv6 address add address=($targetIP . "/64") interface=$WANInterface advertise=no
    /ip dns cache flush
    :log/warning "Локальный WAN IPv6 обновлён → $targetIP"
}

# 3. Проверяем через resolve (только AAAA)
:local resolvedIP ""
:do {
    :set resolvedIP [:resolve $hostname type=ipv6]
    :log info "Роутер видит $hostname → $resolvedIP"
} on-error={
    :log/warning "Не удалось зарезолвить $hostname по AAAA"
    :set resolvedIP ""
}

# 4. Обновляем CF, если нужно
:if ($resolvedIP != $targetIP) do={
    :log/warning "Разница → обновляем CF: $resolvedIP ≠ $targetIP"
	:do {
		/tool fetch \
			url=("https://api.cloudflare.com/client/v4/zones/" . $CFzoneid . "/dns_records/" . $CFrecordid) \
			http-method=put \
			http-header-field=("X-Auth-Email:" . $email . ",X-Auth-Key:" . $CFtoken . ",Content-Type:application/json") \
			http-data=("{\"type\":\"AAAA\",\"name\":\"" . $hostname . "\",\"content\":\"" . $targetIP . "\",\"ttl\":120,\"proxied\":false}") \
			keep-result=no

		:log/info "Cloudflare обновлён → $targetIP"
		:local message ("CF: Updating " . $hostname . " " . $resolvedIP .  " > " . $targetIP)
		:tool fetch url=("https://api.telegram.org/bot$botToken/sendMessage?chat_id=$chatID&text=$message&parse_mode=HTML") keep-result=no
		/ip dns cache flush
	} on-error={
		:log error "CF GET FAILED (RouterOS hides body on HTTP 4xx/5xx)"
		:local message ("CF GET FAILED " . $hostname . " " . $resolvedIP .  " > " . $targetIP)
		:tool fetch url=("https://api.telegram.org/bot$botToken/sendMessage?chat_id=$chatID&text=$message&parse_mode=HTML") keep-result=no
	}

} else={
    :log info "Уже актуально ($resolvedIP) — ничего не делаем"
}

:log info "=== IPv6 DDNS завершён ==="

Обратная связь

    The average number of adverse effects was 3. T max is 23 minutes in females and 32 minutes in males. What other drugs will affect doxercalciferol Viagra natural sin receta. Archived from the original on 2009-08-14.

    Talk to your doctor before using this form of cefadroxil if you have diabetes. What should I tell my healthcare team before starting CABLIVI? There is no FDA guidance on the use of Tetracycline (oral) with respect to specific gender populations https://www.apotheke-rezeptfreie.com/. Opper K, Uder S, Song K Development of Heterogeneous and Homogeneous Platforms for Rapid Analysis of DNA-Protein Interactions.

    Contact Us