Привет! Вижу много скриптов для разных провайдеров или ситуаций. Этот скрипт предназначен для работы в максимально возможном количестве ситуаций и с разными провайдерами, неважно, находитесь ли вы за NAT или у вас публичный IP. В качестве бонуса есть функция "Принудительное обновление каждые X дней". Если вам кажется, что этот скрипт полезен, я могу добавить других провайдеров. Некоторые фрагменты кода взяты из существующих скриптов, опубликованных в вики.
# Параметры
:local username "<ваш логин>"
:local password "<ваш пароль>"
:local hostname "<поддомен.вашпровайдер.net>"
# доступные опции: "http" или "iface"
# - http: будет запрошен внешний сервер и определен ваш публичный IP (полезно для NATted соединений)
# - iface: будет использован IP-адрес, назначенный интерфейсу $iface (см. ниже)
:local discoverBy "iface"
# интерфейс, используемый для получения IP-адреса (только если discoverBy = iface)
:local iface "public-dsl"
# текущие доступные сервисы: "dyndns", "noip" и "changeip"
:local service "changeip"
# количество дней, в течение которых будет принудительно обновляться IP, если он не изменился (помогает поддерживать активность учетной записи)
:local forceUpdate 15
# не изменяйте это, если не знаете, что делаете
:local force
:global lastUpdate
:local currentIP
:if ($discoverBy="http") do={
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
:local result [/file get dyndns.checkip.html contents]
:local resultLen [:len $result]
:local startLoc [:find $result ": " -1]
:set startLoc ($startLoc + 2)
:local endLoc [:find $result "</body>" -1]
:set currentIP [:pick $result $startLoc $endLoc]
} else={
:set currentIP [ /ip address get [find interface=$iface disabled=no] address ]
:for i from=( [:len $currentIP] - 1) to=0 do={
:if ( [:pick $currentIP $i] = "/") do={ :set currentIP [:pick $currentIP 0 $i] }
}
}
# Получить IP из DynDNS для нашего хоста
:local resolvedIP [:resolve $hostname]
# Получить текущую дату в формате mm/DD/YYYY
:local date [ /system clock get date ]
# Преобразовать в YYYYMMDD
:local months ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
:local month [ :pick $date 0 3 ]; :local day [ :pick $date 4 6 ]; :local year [ :pick $date 7 11 ];
:local mm ([ :find $months $month -1 ] + 1);
:if ($mm < 10) do={ :set month ("0" . $mm); } else={ :set month $mm; }
:set date ($year . $month . $day);
:if ([ :typeof $lastUpdate ]=[:nothing] || (($date-$lastUpdate) >= $forceUpdate && $forceUpdate > 0)) do={
:set force true
}
:put ("Current IP: $currentIP ($discoverBy), Last update: $lastUpdate")
# Определить, требуется ли обновление dyndns
:if (($currentIP != $resolvedIP) || ($force = true)) do={
:if ($service = "dyndns") do={
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/output.txt"
}
:if ($service = "noip") do={
/tool fetch user=$username password=$password mode=http address="dynupdate.no-ip.com" \
src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/output.txt"
}
:if ($service = "changeip") do={
/tool fetch user=$username password=$password mode=http address="nic.changeip.com" \
src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/output.txt"
}
:local result [/file get output.txt contents]
:log info ("dynamic-dns-updater: Service = $service, Hostname = $hostname")
:log info ("dynamic-dns-updater: CurrentIP = $currentIP, Resolved IP = $resolvedIP")
:log info ("dynamic-dns-updater: Update result: ".$result)
/ip dns cache flush
:set lastUpdate $date
}
# Параметры
:local username "<ваш логин>"
:local password "<ваш пароль>"
:local hostname "<поддомен.вашпровайдер.net>"
# доступные опции: "http" или "iface"
# - http: будет запрошен внешний сервер и определен ваш публичный IP (полезно для NATted соединений)
# - iface: будет использован IP-адрес, назначенный интерфейсу $iface (см. ниже)
:local discoverBy "iface"
# интерфейс, используемый для получения IP-адреса (только если discoverBy = iface)
:local iface "public-dsl"
# текущие доступные сервисы: "dyndns", "noip" и "changeip"
:local service "changeip"
# количество дней, в течение которых будет принудительно обновляться IP, если он не изменился (помогает поддерживать активность учетной записи)
:local forceUpdate 15
# не изменяйте это, если не знаете, что делаете
:local force
:global lastUpdate
:local currentIP
:if ($discoverBy="http") do={
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
:local result [/file get dyndns.checkip.html contents]
:local resultLen [:len $result]
:local startLoc [:find $result ": " -1]
:set startLoc ($startLoc + 2)
:local endLoc [:find $result "</body>" -1]
:set currentIP [:pick $result $startLoc $endLoc]
} else={
:set currentIP [ /ip address get [find interface=$iface disabled=no] address ]
:for i from=( [:len $currentIP] - 1) to=0 do={
:if ( [:pick $currentIP $i] = "/") do={ :set currentIP [:pick $currentIP 0 $i] }
}
}
# Получить IP из DynDNS для нашего хоста
:local resolvedIP [:resolve $hostname]
# Получить текущую дату в формате mm/DD/YYYY
:local date [ /system clock get date ]
# Преобразовать в YYYYMMDD
:local months ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
:local month [ :pick $date 0 3 ]; :local day [ :pick $date 4 6 ]; :local year [ :pick $date 7 11 ];
:local mm ([ :find $months $month -1 ] + 1);
:if ($mm < 10) do={ :set month ("0" . $mm); } else={ :set month $mm; }
:set date ($year . $month . $day);
:if ([ :typeof $lastUpdate ]=[:nothing] || (($date-$lastUpdate) >= $forceUpdate && $forceUpdate > 0)) do={
:set force true
}
:put ("Current IP: $currentIP ($discoverBy), Last update: $lastUpdate")
# Определить, требуется ли обновление dyndns
:if (($currentIP != $resolvedIP) || ($force = true)) do={
:if ($service = "dyndns") do={
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/output.txt"
}
:if ($service = "noip") do={
/tool fetch user=$username password=$password mode=http address="dynupdate.no-ip.com" \
src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/output.txt"
}
:if ($service = "changeip") do={
/tool fetch user=$username password=$password mode=http address="nic.changeip.com" \
src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/output.txt"
}
:local result [/file get output.txt contents]
:log info ("dynamic-dns-updater: Service = $service, Hostname = $hostname")
:log info ("dynamic-dns-updater: CurrentIP = $currentIP, Resolved IP = $resolvedIP")
:log info ("dynamic-dns-updater: Update result: ".$result)
/ip dns cache flush
:set lastUpdate $date
}
