Post subject: why this script does work? who can help me
Posted: Fri Dec 07, 2007 9:42 pm
just joined
Joined: Mon Dec 03, 2007 10:37 am Posts: 6
Karma: 0
: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....
Cleaned from bad syntax (you have more than those 2 mentioned above):
Code:
: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
Post subject: Re: why this script does work? who can help me
Posted: Sat Dec 08, 2007 6:04 pm
just joined
Joined: Mon Dec 03, 2007 10:37 am Posts: 6
Karma: 0
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.
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.
Users browsing this forum: No registered users and 4 guests
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum