[Mikrotik] błąd w skrypcie?

Witam!

Mój problem polega na tym że mam skrypt do aktualizacji adres publicznego IP do DDNS sęk w tym że mam do skryptu przypisany automat na uruchomienie co 2 minuty. Skrypt ten tworzy plik txt z aktualnym adresem i prawdopodobnie go porównuje przed wysłaniem w świat sęk w tym że gdy mój adres się zmieni skrypt zmienia go w pliku ale obstawiam że jeszcze nie ma jak go wysłać bo brakuje mu sieci ?? w każdym bądź razie ie zmienia mi się adres w DDNS. Jak zrobię to ręcznie na zasadzie suń plik txt z mikrotika z adresem i uruchom skrypt bądź uruchomi się z automatu to podaje adres już do DDNS, po wykonanym  skrypcie już plik tworzy się na nowo.

Podaje skrypt może ktoś coś pomoże choćby zniwelować ten plik niech wysyła za każdym razem czy coś innego.

############## Script FreeDNS.afraid.org ##################
############## PARSER EDITION ##################
############## CREATED LESHIY_ODESSA ##################
   
# Specify the "Direct URL", which is https://freedns.afraid.org/dynamic/
# If RouterOS version 5.xx, then remove from the URL encryption - "https" change this to "http". Also see below.
# In front of the sign "?" put a backslash "\".
:global "direct-url" ""

# Specify the URL API "ASCII"
# Log in under your account and open the page https://freedns.afraid.org/api/
# Then copy the URL of your site - Available API Interfaces : ASCII (!!! NOT XML !!!)
# ATTENTION!!!! Before the question mark, put a backslash "\".
# If RouterOS version 5.xx, then remove from the URL encryption - "https" change this to "http".
:global "api-url" ""
    
# Specify your domain or subdomain.
:global "dns-domain" ""

# Define variables for the external (WAN) interface
# Case sensitive.
:global "out-interface" "pppoe-out1"
       
# !!!!!!!!!!!!!!!!! Nothing more do not need to edit!!!!!!!!!!!!!!!!!
       
# Check whether the file with the IP domain - freedns.txt
:if ([:len [/file find name=freedns.txt]] > 0) do={
} else={
/tool fetch url=$"api-url" dst-path="/freedns.txt"
}
# Find out the IP address of the domain using the API and parsing.
# Split the file
:local "result" [/file get freedns.txt contents]
:local "startloc" ([:find $"result" $"dns-domain"] + ([:len $"dns-domain"] + 1))
:local "endloc" ([:find $"result" $"direct-url" -1] -1)
:global "dns-domain-ip" [:pick $"result" $"startloc" $"endloc"]
       
# Find the current IP address on the external interface
:global "current-ip" [/ip address get [find interface=$"out-interface"] address]
    
# Obtained from IP addresses to be excluded subnet mask
:set "current-ip" [:pick $"current-ip" 0 ([:len $"current-ip"]-3) ]
       
# Compare the external IP with the IP address of the DNS domain.
:if ($"current-ip" != $"dns-domain-ip") do={

# If different, then sent to freedns.afraid.org our external IP by using Direct URL
:log info ("Service Dynamic DNS: old IP address $"dns-domain-ip" for $"dns-domain" CHANGED to -> $"current-ip"")
/tool fetch url=$"direct-url" keep-result=no
# Download the file with the new IP after 5 sec.
:delay 5
/tool fetch url=$"api-url" dst-path="/freedns.txt"
} else={
# Not to clog the log, you need to comment out this line.
:log info ("IP address is NOT CHANGED, the update is not required")
}
    
# Since version RouterOS version 6.0rc12 supported encryption /tool fetch mode=https
# In :global "direct-url" need to change to httpS://
# For RouterOS version 6.xx
# /tool fetch mode=https url=$"direct url"
# :global "direct-url" "https://freedns.afraid.org/dynamic/update.php\?UVdjU2lzQmQwSkdjZW9aWkNleTdJdXFtOjg2NTI0NzE="

# http://wiki.mikrotik.com/wiki/Manual:Scripting
# http://wiki.mikrotik.com/wiki/Manual:Scripting-examples
# http://wiki.mikrotik.com/wiki/Manual:Tools/Fetch
# http://forum.ixbt.com/topic.cgi?id=14:60498-86#2373

##############Script FreeDNS.afraid.org##################

 

Jak obstawiasz, że sieć nie jest osiągalna, to może pokombinuj z jakimś sleepem.

:log info ("Service Dynamic DNS: old IP address $"dns-domain-ip" for $"dns-domain" CHANGED to -> $"current-ip"") 
:delay 10

ok próbuje jeśli nie zadziała odezwę się a na razie dzięki :slight_smile:

Po co skrypt zapisuje ip do txt? Skrypt powinien aktualizować ip w usłudze ddns, ja mam taki skrypt właśnie na jednym RBku.

Nie wiem po co tez mnie to głowi jeśli chodzi o skrypty dopiero się szkole. MT na RB mam może z 2 miesiące, ale dobrze mi idzie. Skrypt ten wziąłem ze strony od DDNS. Jak kolega wcześniej pisał opóźniłem wysyłkę przez :delay ale to nie pomogło i wpadł mi w pracy pomysł dlaczego ja tego pliku przez skrypt nie usuwam przed wykonaniem całej reszty.Dodałem przed chwilką linijkę która ten plik kasuje przed wykonaniem i eureka udało się. A co do skryptu jeśli masz coś lepszego a masz wolę się podzielić to chętnie Cię wysłucham.

Ja korzystam z takiego skryptu, jest prostszy i nie wymaga pliku txt. Skrypt pisany dla usługi DynuDNS.

 

/system script
add name=Dynu
policy=read,write,test
source=":global ddnsuser your_Dynu_username
:global ddnspass "your_Dynu_password"
:global theinterface "your_LAN_name"
:global ddnshost "your_Dynu_hostname"
:global ipddns [:resolve $ddnshost];
:global ipfresh [/ip address get [/ip address find interface=$theinterface] address ]
:if ([:typeof $ipfresh] = nil ) do={
:log info ("DynuDDNS: No IP address on $theinterface .")
} else={
:for i from=( [:len $ipfresh] - 1) to=0 do={
:if ( [:pick $ipfresh $i] = "/") do={
:set ipfresh [:pick $ipfresh 0 $i];
}
}
:if ($ipddns != $ipfresh) do={
:log info ("DynuDDNS: IP-Dynu = $ipddns")
:log info ("DynuDDNS: IP-Fresh = $ipfresh")
:log info "DynuDDNS: Update IP needed, Sending UPDATE...!"
:global str "/nic/update?hostname=$ddnshost&myip=$ipfresh"
/tool fetch address=api.dynu.com src-path=$str mode=http user=$ddnsuser password=$ddnspass dst-path=("/Dynu.".$ddnshost)
:delay 1
:global str [/file find name="Dynu.$ddnshost"];
/file remove $str
:global ipddns $ipfresh
:log info "DynuDDNS: IP updated to $ipfresh!"
} else={
:log info "DynuDDNS: dont need changes";
} } [/code]

W miejsce

/tool fetch url=

Podajesz IP lub domenę serwera DDNS. No chyba, że sama usług DDNS wymaga pobrania pliku txt i porównanie go z lokalnym plikiem.

No u mnie to wygląda tak że mam unikalny adres URL lub adres API do podania adresu IP. Jeśli masz czas zaglądnij jak wygląda aktualizacja stanu dla freedns.afraid.org, ja w ogóle nie muszę podawać loginu ani hasła w skrypcie.