Skip to content

Instantly share code, notes, and snippets.

@ergolyam
Created December 22, 2024 01:14
Show Gist options
  • Select an option

  • Save ergolyam/da509cdc66db9a78572037a55b9c5322 to your computer and use it in GitHub Desktop.

Select an option

Save ergolyam/da509cdc66db9a78572037a55b9c5322 to your computer and use it in GitHub Desktop.
6in4 update Dyn IP with api for mikrotik
# MikroTik Script: 6in4.rsc
# Purpose: Update PPPoe IP dynamically
:local apiKey "api_key"
:local tunnelId "tunnel_id"
:local fileName "last_pppoe_ip2.txt"
:local lastIP
:local currentIP
:if ([/file find name=$fileName] = "") do={
/file print file=$fileName
:log info "File $fileName created."
}
:if ([/file find name=$fileName] != "") do={
:set lastIP [/file get [/file find name=$fileName] contents]
}
# command to get ip from pppoe interface
:set currentIP [/ip address get [find interface="pppoe-out1"] address]
:if ($currentIP != $lastIP) do={
:local url "https://6in4.ru/tunnel/$apiKey/$tunnelId"
:local jsonIP [:pick $currentIP 0 [:find $currentIP "/"]]
/tool fetch url=$url http-method=put http-header-field="Content-Type: application/json,accept: */*,accept-encoding:*" http-data="{\"ipv4remote\":\"$jsonIP\"}" dst-path=/dev/null keep-result=no
/interface 6to4 set sit1 local-address=$jsonIP
:file set [/file find name=$fileName] contents=$currentIP
:log info "6in4 updated to $currentIP."
} else={
:log info "No changes in IP address. Update not required."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment