Community discussions

MikroTik App
 
User avatar
own3r1138
Long time Member
Long time Member
Topic Author
Posts: 689
Joined: Sun Feb 14, 2021 12:33 am
Location: Pleiades
Contact:

Issue in scripting

Sun Oct 02, 2022 7:07 pm

I tried to write a script in which, I needed to get a local address of a dynamic interface like PPPoE but failed to do so.
Any help would be appreciated.

Something like this but I couldn't find a way to make it work.
# get local-address of the dynamic interface.
:local locoIP [get [find where comment=$commentN] local-address]
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: Issue in scripting

Sun Oct 02, 2022 7:34 pm

Are we talking about a dynamic IP address or a dynamic interface (as in /interface pppoe server print)? I mean, if you don't know the address but you do know the name of the interface, it is simply :local locoIP [/ip address get [find interface=the-interface-name] address], but if you don't know the interface name and only have the user name from the /ppp secret, it is :local locoIP ([/interface sstp-server monitor [find user=kotel] once as-value]->"local-address") because the interface name may be allocated statically so the <pppoe-username> may not always be true.
 
User avatar
own3r1138
Long time Member
Long time Member
Topic Author
Posts: 689
Joined: Sun Feb 14, 2021 12:33 am
Location: Pleiades
Contact:

Re: Issue in scripting

Sun Oct 02, 2022 8:43 pm

Hi,
Thank you, I tried to replicate it. It seems okay till the last section of the script :(
It looks like the problem starts from there or perhaps shows itself when I added the line.
;log info "IPIP Tunnel address start"

:local interfaceN PPPOE
:local commentN Name

:local locoIP [/ip address get [find interface=$interfaceN] address]
:local tunnelIP [/interface ipip get [find where comment=$commentN] local-address]

# It looks like the problem starts from here.
:if ($locoIP != $tunnelIP) do={
/interface ipip set $tunnelIP local-address=$locoIP
;log info "IP Tunnel address updated"
}

 
msatter
Forum Guru
Forum Guru
Posts: 2912
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Issue in scripting

Sun Oct 02, 2022 9:08 pm

;log has to be :log....twice
 
User avatar
own3r1138
Long time Member
Long time Member
Topic Author
Posts: 689
Joined: Sun Feb 14, 2021 12:33 am
Location: Pleiades
Contact:

Re: Issue in scripting

Sun Oct 02, 2022 9:55 pm

Thank you, I changed them, still doesn't work. It does work in another Script But, I couldn't find where the problem is in this one.
:log info "IPIP Tunnel address start"

:local interfaceN PPPOE
:local commentN Name

:local locoIP [/ip address get [find interface=$interfaceN] address]
:local tunnelIP [/interface ipip get [find where comment=$commentN] local-address]

:if ($locoIP != $tunnelIP) do={
/interface ipip set $tunnelIP local-address=$locoIP
:log info "IPIP Tunnel address updated"
}
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: Issue in scripting

Sun Oct 02, 2022 9:56 pm

$tunnelIP is an IP address, so I'd assume you had in mind /interface ipip set [find where comment=$commentN] local-address=$locoIP ?

But normally this should not be necessary - if you do not specify local-address for an IPIP tunnel, it will choose the address of the output interface chosen by routing as the source one for the outgoing transport packets, and it will accept transport packets coming from the remote-address to any of its own addresses. A src-nat rule may break this, but a masquerade one should not as the connections are removed when the address they've got as reply-dst-address changes.

I.e. from my point of view, the challenge is not to track the WAN IP locally but to inform the remote party about its change if the remote party has multiple IPIP tunnels.
 
User avatar
Znevna
Forum Guru
Forum Guru
Posts: 1347
Joined: Mon Sep 23, 2019 1:04 pm

Re: Issue in scripting  [SOLVED]

Sun Oct 02, 2022 10:06 pm

Getting the IP from /ip address will be in CIDR format (x.x.x.x/32 or x.x.x.x/24 or x.x.x.x/whatever) which I doubt it will match with whatever is in local-address of an IPIP tunnel which is just x.x.x.x.
Use the local-address from the pppoe-client as @sindy suggested above.
Any of these two lines should work in your script replacing your line.
:local locoIP ([/interface pppoe-client monitor [find name=$interfaceN] once as-value]->"local-address")
:local locoIP ([/interface pppoe-client monitor $interfaceN once as-value]->"local-address")
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: Issue in scripting

Sun Oct 02, 2022 10:18 pm

Or the other way around, convert the address without the CIDR part (the one from the /interface ipip configuration) to a string and add "/32" to it:

:put ([/ip address get [find interface=pptp-out1] address]=([:tostr ([/interface pptp-client monitor pptp-out1 once as-value]->"local-address")] . "/32")) gives true.
 
User avatar
own3r1138
Long time Member
Long time Member
Topic Author
Posts: 689
Joined: Sun Feb 14, 2021 12:33 am
Location: Pleiades
Contact:

Re: Issue in scripting

Mon Oct 03, 2022 12:16 am

@Znevna
I settle down with Sindy's suggestion that I don't need it. Although I tried to work it out, I failed. I have to grasp a better understanding of syntax first.

@Sindy
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAArFQAA
8AAXmKgBAADwABeYqAEAAGAAF5ioAQAAYAAXmKgBAAAAsB6YqAEAAABACAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
Both of you, I appreciate your time and effort.

Who is online

Users browsing this forum: DanMos79, haedertowfeq, jvanhambelgium, Jörg, kg5iru, monotsc, unhuzpt, vingjfg and 58 guests