Mikrotik RouterOS FreeDNS Update 스크립트
1. http://freedns.afraid.org
2. 좌측 메뉴 DynamicDNS 클릭
3. 로그인
4. Programmer's XML API 클릭
5. ASCII를 클릭하면 소유한 URL별 API Interface URL을 확인 할수 있다. 이것을 복사한다.
6. Mikrotik 장비에서 System > Scripts 에서 아래 스크립트를 신규 작성 추가한다.
주의! : URL 문자열에 음표(?)가 있을 텐데 이것 앞에 '\'를 추가해주어야만 한다.
# 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" "http://API_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" "http://API_URL"
# Specify your domain or subdomain.
:global "dns-domain" "갱신하고자 하는 URL, 예, mine.mooo.com"
# Define variables for the external (WAN) interface
# Case sensitive.
:global "out-interface" "Mikrotik 장비의 인터넷 인터페이스 이름, 예, ether1"
# !!!!!!!!!!!!!!!!! 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")
}
'Network' 카테고리의 다른 글
openvpn-monitor 구성하기 (0) | 2022.02.04 |
---|---|
Ubuntu 18.04 VPN PPTP 설정법 (0) | 2018.06.07 |