Community discussions

MikroTik App
 
qudama
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 57
Joined: Mon Feb 24, 2014 2:26 am

Copy Dynamic ip pptp-out1 to nat address

Mon Oct 04, 2021 10:27 pm

Hello,
i need a script that copy address from the dynamic pptp-out1 from ip address to ip firewall nat and set to address
 
joegoldman
Forum Veteran
Forum Veteran
Posts: 766
Joined: Mon May 27, 2013 2:05 am

Re: Copy Dynamic ip pptp-out1 to nat address

Tue Oct 05, 2021 12:44 am

You can use ppp profiles to create on-up and on-down scripts. on-up script has a variable passed in for Local Address (Address assigned to the interface) as '$local-address'

So it'd be something similar to this (untested):

/ip firewall nat set [ find comment="PPTP UPDATE" ]  to-address=$local-address

This will find the NAT rule with comment 'PPTP UPDATE' and set the to-address as the assigned address. I find comments the easiest unique way to find a rule but you can obviously change the FIND statement to identify the rule however you want.
 
qudama
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 57
Joined: Mon Feb 24, 2014 2:26 am

Re: Copy Dynamic ip pptp-out1 to nat address

Tue Oct 05, 2021 6:17 pm

Thank alot i get solved it :)




:global new
:global old
:global status
:set status [/interface get [/interface find name=("pptp-out1")] running]
:if ($status=true) do={
:set new [/ip address get [/ip address find dynamic=yes interface=("pptp-out1")] address]
:set new [:pick $new 0 ([:len $new] -3)]
:set old [/ip firewall nat get [find comment=("Loopback")] to-addresses]
:if (!($new=$old)) do={
/ip firewall nat set [/ip firewall nat find comment=("Loopback")] to-addresses=$new
}}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Copy Dynamic ip pptp-out1 to nat address

Tue Oct 05, 2021 6:35 pm

Better on this way:
:global status [/interface get pptp-out1 running]
:if ($status) do={
    :global old [/ip firewall nat get [find where comment="Loopback"] to-addresses]
    :global new [/ip address get [find where dynamic=yes and interface="pptp-out1"] address] 
    :set new [:pick $new 0 [:find $new "/"] ]
    :if ($new != $old) do={
        /ip firewall nat set [find where comment="Loopback"] to-addresses=$new
    }
}
 
qudama
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 57
Joined: Mon Feb 24, 2014 2:26 am

Re: Copy Dynamic ip pptp-out1 to nat address

Tue Oct 05, 2021 7:35 pm

Better on this way:
:global status [/interface get pptp-out1 running]
:if ($status) do={
    :global old [/ip firewall nat get [find where comment="Loopback"] to-addresses]
    :global new [/ip address get [find where dynamic=yes and interface="pptp-out1"] address] 
    :set new [:pick $new 0 [:find $new "/"] ]
    :if ($new != $old) do={
        /ip firewall nat set [find where comment="Loopback"] to-addresses=$new
    }
}
Noted with thanksssssssssssssssssssss

Who is online

Users browsing this forum: UkRainUa and 27 guests