Community discussions

 
jtrain01
just joined
Topic Author
Posts: 3
Joined: Wed May 15, 2019 10:27 pm

Need help with script

Wed May 15, 2019 10:51 pm

I have RB1100AHx4 v644.3 with pcc load balancing.
Both ISP gives dynamic IP so i need to change mangle rules and routes everytime. I've tried creating a script for this but i think my luck has run out.

Can't figure out why it doesn't work.

Anyone care to help?
:log info "checking gateway and address";


:if ($newgwIP != $routeIP) do={


:put "gateway ip $routeIP changed to $newgwIP";
}



:if ($newgwIP != $routeIP1) do={


:put "gateway ip $routeIP1 changed to $newgwIP";
}


:for i from=( [:len $newIP] - 1) to=0 do={
        :if ( [:pick $newIP $i] = "/") do={ 
            :set newIP [:pick $newIP 0 $i]
        } 
    }
    
    :if ($newIP != $fwIP) do={
         :set fwIP $newIP

:log info "done changing fw dst address and route gateway";
I already set the variables in terminal and they are working but not changing any
Last edited by jtrain01 on Thu May 23, 2019 1:04 pm, edited 1 time in total.
 
jtrain01
just joined
Topic Author
Posts: 3
Joined: Wed May 15, 2019 10:27 pm

Re: Need help with script

Thu May 23, 2019 6:19 am

Lokos like nobody is interested.
Any example or a workaround is all i need. Im using pcc load balance with 2 wan with dynamic ip.

I have rb1100AHx4
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1303
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Need help with script

Thu May 23, 2019 1:09 pm

Do you have a system there your gateway does changes for the clients?
Can you not put all gateway in a group
/interface list add name=WAN
/interface list member add interface=ether1 list=WAN
/interface list member add interface=xxx list=WAN
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
jtrain01
just joined
Topic Author
Posts: 3
Joined: Wed May 15, 2019 10:27 pm

Re: Need help with script

Sat May 25, 2019 3:58 pm

I managed to fix this by fiddling with the commands available in the terminal.

Here's one for my 1st WAN interface.
:global newgwIP
:global routeIP
:global newIP
:global fwIP
:global newgwIP [/ip dhcp-client get [find interface="ISP1-PLDTHomeFibr"] gateway];
:global routeIP [/ip route get [find comment="wanmarkgwIP1"] gateway];
:global routeIP1 [/ip route get [find comment="wanmarkgwIP2"] gateway];
:if ($newgwIP != $routeIP) do={


:put "gateway ip $routeIP changed to $newgwIP";

:set routeIP [/ip route set [find comment="wanmarkgwIP1"] gateway=$newgwIP];}

:if ($newgwIP != $routeIP1) do={


:put "gateway ip $routeIP1 changed to $newgwIP";

:set routeIP1 [/ip route set [find comment="wanmarkgwIP2"] gateway=$newgwIP];}

:log info "done updating route with $newgwIP";
:log info "updating firewall mangle";

:global newIP [/ip dhcp-client get [find interface="ISP1-PLDTHomeFibr"] address];
:global fwIP [/ip firewall mangle get [find comment="isp1"] dst-address];
:for i from=( [:len $newIP] - 1) to=0 do={
        :if ( [:pick $newIP $i] = "/") do={
:set newIP [:pick $newIP 0 $i]
}}

:if ($newIP != $fwIP) do={

:set fwIP [/ip firewall mangle set [find comment="isp1"] dst-address=$newIP];}

:log info "done updating firewall mangle with $newIP"
:log info "vpn should work"
If theres anything suggestion you can give though i will really appreciate it.
And thx for replying too anyway

Who is online

Users browsing this forum: No registered users and 4 guests