Right now you’re using the same WANip variable for what should be 2 different variables.
On the last line, it’s a better idea to use [find] instead of a number (set 0) because the number doesn’t exist unless you do a print command prior to, and even then the number may change if items are added or removed. Using [find], you want to search for something in that item that won’t change. For the example, by adding a unique comment to the policy, you can use the [find] command as I did below.
:local WANip1 [/ip address get [find interface=“ether1-gateway”] address]
:log info “Interface IP is $WANip1”
:local WANip2 [:pick “$WANip1” 0 ([:len $WANip1] - 3)]
:log info “IP sans the slash notation is $WANip2”
/ip ipsec policy set [find comment=“myIPsec”] src-address=$WANip1 sa-src-address=$WANip2
I have a script to compare whether WAN IP address has been changed and another script to update sa-src-address. Do I need to add something else to the script like kill remote peers and flush installed SAs?
Here is the script I wrote... It does EoIP over IPSec. Basically it looks for IPSec Peers with a comment that looks like
"+eoip+" ... it then looks for the policy, eoip tunnel, etc that all share the same comment. You can use this to update as many as you want...
No worries. I actually have a ton of scripts for different things I wrote over time. I’d love to put them on the WIKI, but its not open for editing any more.
Feel free to do whatever you want with it… I have versions for EOIP, IPIP, Straight IPSec, etc… … I also have a massive script with ALL of them built in… it just looks at the comments.. e.g. +ipip+hostname, +eoip+hostname, etc.