# get actual values of sa-dst-address and sa-src-address
:global actual [/ip ipsec policy get 1 sa-dst-address]
:global actuallocal [/ip ipsec policy get 1 sa-src-address]
:global peer [/ip ipsec peer get 0 address]
#change policy if remote or local ip changed
:if ($RemoteIp !=$actual) do={
:log info "CheckRemoteIp: Update required $RemoteIp"
/ip ipsec policy set 1 sa-dst-address=$RemoteIp sa-src-address=$LocalIp} else= {:log info "No need to update"}
/ip ipsec peer set 0 address=$RemoteIp
:log info "Remote update done, next local"
:if ($LocalIp !=$actuallocal) do={
:log info "CheckRemoteIp: Update required $LocalIp"
/ip ipsec policy set 1 sa-dst-address=$RemoteIp sa-src-address=$LocalIp} else= {:log info "No need to update"}
/ip ipsec peer set 0 address=$RemoteIp
:log info "IPSEC update done"
***ภายหลัง Script ทำงานก็จะทำการอัพเดรต IP wan ของทั้ง HQ และ Site
ในส่วนของ Policies และ Peer ให้อัตโนมัติ (ของเดิมที่ตัวอย่างจะระบุใส่เป็น 1.1.1.1 , 2.2.2.2 ให้ก่อนหน้านั้น)**
# get actual values of sa-dst-address and sa-src-address
:global actual [/ip ipsec policy get 1 sa-dst-address]
:global actuallocal [/ip ipsec policy get 1 sa-src-address]
:global peer [/ip ipsec peer get 0 address]
#change policy if remote or local ip changed
:if ($RemoteIp !=$actual) do={
:log info "CheckRemoteIp: Update required $RemoteIp"
/ip ipsec policy set 1 sa-dst-address=$RemoteIp sa-src-address=$LocalIp} else= {:log info "No need to update"}
/ip ipsec peer set 0 address=$RemoteIp
:log info "Remote update done, next local"
:if ($LocalIp !=$actuallocal) do={
:log info "CheckRemoteIp: Update required $LocalIp"
/ip ipsec policy set 1 sa-dst-address=$RemoteIp sa-src-address=$LocalIp} else= {:log info "No need to update"}
/ip ipsec peer set 0 address=$RemoteIp
:log info "IPSEC update done"
***ภายหลัง Script ทำงานก็จะทำการอัพเดรต IP wan ของทั้ง HQ และ Site
ในส่วนของ Policies และ Peer ให้อัตโนมัติ (ของเดิมที่ตัวอย่างจะระบุใส่เป็น 1.1.1.1 , 2.2.2.2 ให้ก่อนหน้านั้น)**