Community discussions

 
joylu
just joined
Topic Author
Posts: 6
Joined: Mon Dec 03, 2007 9:37 am

why this script does work? who can help me

Fri Dec 07, 2007 8:42 pm

:local new-address
:local status
:local x
:set x 2
:for i from=1 to=$x do={
:set staus [/interface get [/interface find name=("ppoe")] runnig]
:if ($status=ture) do={
:set new-address [/ip address get [/ip address find dynamic=yes interface=("ppoe")] address]
:set new-address [:pick $new-address 0 ([:len $new-address] -3)]
/ip fir nat set [/ip fir nat find comment=$i] to-addresses=$new-address
}
}

tip: 1.2 this my dstnat rule's name. ppoe is interface name. i was hope this script can Automatic mapping port . whats wrong? why does work? im very confuse....
 
changeip
Forum Guru
Forum Guru
Posts: 3803
Joined: Fri May 28, 2004 5:22 pm

Re: why this script does work? who can help me

Fri Dec 07, 2007 8:45 pm

you misspelled 'true'. you also misspelled 'running'.
Colo and Wholesale Bandwidth Available! Sales at SanDiegoBroadband dot com
 
joylu
just joined
Topic Author
Posts: 6
Joined: Mon Dec 03, 2007 9:37 am

Re: why this script does work? who can help me

Sat Dec 08, 2007 12:07 pm

:local new-address
:local status
:local x
:set x 2
:for i from=1 to=$x do={
:set staus [/interface get [/interface find name=("ppoe")] 'running']
:if ($status='ture') do={
:set new-address [/ip address get [/ip address find dynamic=yes interface=("ppoe")] address]
:set new-address [:pick $new-address 0 ([:len $new-address] -3)]
/ip fir nat set [/ip fir nat find comment=$i] to-addresses=$new-address
}
}

thx for u reply. but also does work.. my ros is 2.9.27
best regard
 
User avatar
Dragonmen
Frequent Visitor
Frequent Visitor
Posts: 72
Joined: Thu Jun 16, 2005 6:20 pm
Location: Sabac, Serbia
Contact:

Re: why this script does work? who can help me

Sat Dec 08, 2007 2:23 pm

Cleaned from bad syntax (you have more than those 2 mentioned above):
:local new-address
:local status
:local x
:set x 2
:for i from=1 to=$x do={
:set status [/interface get [/interface find name="ppoe"] running]
:if ($status=true) do={
:set new-address [/ip address get [/ip address find dynamic=yes interface="ppoe"] address]
:set new-address [:pick $new-address 0 ([:len $new-address] -3)]
/ip firewall nat set [/ip fir nat find comment=$i] to-addresses=$new-address
}
}
Notice: "[:pick $new-address 0 ([:len $new-address] -3)]" - how do you know the last number in ip address will have 3 digits?
interface name "ppoe" is questionable (did you type it right, the correct spelling is "pppoe"
Avoid for x from... at all costs - that causes only problems
 
joylu
just joined
Topic Author
Posts: 6
Joined: Mon Dec 03, 2007 9:37 am

Re: why this script does work? who can help me

Sat Dec 08, 2007 5:04 pm

DEAR DRAGONMEN
thx for you interset. im follow u guide check my script agagin. im preety sure about that my interface name is "ppoe " and i have no idea this line :set new-address [:pick $new-address 0 ([:len $new-address] -3)] whats mean. if i wanna make ros automatic mapping port. how should i do? can u write a script for me?
thx a loooooooooooooooot.
best regard.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5921
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: why this script does work? who can help me

Sat Dec 08, 2007 7:11 pm

:set new-address [:pick $new-address 0 ([:len $new-address] -3)]

this is bad, because in some cases you will get incorrect IP. To do this correctly you must search for slash '/' from new-address then strip all characters starting from '/' position. Now you will get correct ip.


/ip firewall nat set [/ip fir nat find comment=$i] to-addresses=$new-address this line is in for loop, it means that you have two identical NAT rules? Why?
Also I think that there is absolutely no need to write this script, instead of srcnat you can use masquerade, it will solve dynamic IP problem.

Who is online

Users browsing this forum: No registered users and 6 guests