Community discussions

MikroTik App
 
Freman
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 76
Joined: Thu Jul 01, 2004 8:49 am

Manipulation

Fri Oct 08, 2004 9:49 am

Is there any way to manipulate strings with mikrotik scripting?

IE: I've got "192.168.0.8/32" as a string from /ip firewall mangle src-address but now I want to compare it with /ip address (use it with /ip address find address=$xx)

So I'm looking to strip the /32 from it...

Ideas?
 
edzix
Member
Member
Posts: 335
Joined: Thu Jul 01, 2004 3:01 pm
Location: Latvia

Fri Oct 08, 2004 10:09 am

you will be able to manipulate with strings in version 2.9. In currently supported RouterOS version it's not possible, but maybe you can try to use preferred-source parameter which could be found under '/ip route' menu.

Edgars
 
Freman
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 76
Joined: Thu Jul 01, 2004 8:49 am

Fri Oct 08, 2004 10:29 am

Ah, thanks, yes I'm positive that will work just as well...


Ok folks, here you go, a script to add and remove ip's from mangle that checks to see if it needs to add/remove before adding/removing

Wack it in an interval job and it can check for comming and going of people

AddToMangle
:foreach i in=[interface find type=pppoe-in] do= { 
:foreach n in=[/ip address find interface=$i] do={
:global a;  :set a[/ip address get $n network];
:put ("Checking on " . $a . "/32")
:if ([/ip firewall mangle find src-address=($a . "/32")]="") do={
 /ip firewall mangle add src-address=($a . "/32") p2p=all-p2p action=passthrough mark-flow=p2p-out comment=$a
 /ip firewall mangle add dst-address=($a . "/32") p2p=all-p2p action=passthrough mark-flow=p2p-in comment=$a
}
}
}
RemoveFromMangle
:foreach i in=[/ip firewall mangle find mark-flow=p2p-out] do= { 
:global a;  :set a [/ip firewall mangle get $i src-address];
:log message=("Checking on " . $a )
:if ([/ip route find dst-address=$a]="") do={
:foreach n in=[/ip firewall mangle find dst-address=$a] do={
/ip firewall mangle remove $n
}
 /ip firewall mangle remove $i
}
}
 
edzix
Member
Member
Posts: 335
Joined: Thu Jul 01, 2004 3:01 pm
Location: Latvia

Fri Oct 08, 2004 10:36 am

can you please post it in form taken from '/system script edit <script name> source'?

Edgars
 
Freman
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 76
Joined: Thu Jul 01, 2004 8:49 am

Fri Oct 08, 2004 3:11 pm

Sure, first thing monday morning, unless I have an excuse to return to the office between now and then

I just used winbox to write them, you pretty much just go to system->scripting + give the script a name, and paste the code in

Who is online

Users browsing this forum: BartoszP, Bing [Bot], eworm and 165 guests