MUM 2010
It is currently Tue Feb 09, 2010 5:13 am

All times are UTC + 2 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: why this script does work? who can help me
PostPosted: Fri Dec 07, 2007 9:42 pm 
Offline
just joined

Joined: Mon Dec 03, 2007 10:37 am
Posts: 6
: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....


Top
 Profile  
 
 Post subject: Re: why this script does work? who can help me
PostPosted: Fri Dec 07, 2007 9:45 pm 
Offline
Forum Guru
Forum Guru

Joined: Fri May 28, 2004 5:22 pm
Posts: 2996
you misspelled 'true'. you also misspelled 'running'.

_________________
Colo and Wholesale Bandwidth Available! Sales at ChangeIP dot com


Top
 Profile  
 
 Post subject: Re: why this script does work? who can help me
PostPosted: Sat Dec 08, 2007 1:07 pm 
Offline
just joined

Joined: Mon Dec 03, 2007 10:37 am
Posts: 6
: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


Top
 Profile  
 
 Post subject: Re: why this script does work? who can help me
PostPosted: Sat Dec 08, 2007 3:23 pm 
Offline
Frequent Visitor
Frequent Visitor
User avatar

Joined: Thu Jun 16, 2005 6:20 pm
Posts: 71
Location: Sabac, Serbia
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


Top
 Profile  
 
 Post subject: Re: why this script does work? who can help me
PostPosted: Sat Dec 08, 2007 6:04 pm 
Offline
just joined

Joined: Mon Dec 03, 2007 10:37 am
Posts: 6
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.


Top
 Profile  
 
 Post subject: Re: why this script does work? who can help me
PostPosted: Sat Dec 08, 2007 8:11 pm 
Offline
Staff
Staff
User avatar

Joined: Wed Feb 07, 2007 1:45 pm
Posts: 1790
Location: Latvia
: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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 2 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
MUM Poland and MUM China free REGISTRATION OPEN