Page 1 of 1

Extract part of IP address

Posted: Mon May 30, 2011 7:24 pm
by el berto
Hi, I'm working with DHCP device, so I configured routerboard for DHCP.
I obtain IP address such as "192.168.33.81", then I have to set gateway (192.168.33.1) and dns (192.168.33.1).
So, how can I extract the "192.168.33" from IP address?
Thanks.

Re: Extract part of IP address

Posted: Mon May 30, 2011 7:55 pm
by crix75
Hi ,
Can you try with PICK

Example:
: global ipaddress ;
: set ipaddress [ pick "192.168.33.1" 0 10 ] ;
Bye

Cris

Re: Extract part of IP address

Posted: Mon May 30, 2011 8:20 pm
by petrn
Hi,

to parse IP from interface:
:local iface "pppoe-out1"
:local ip [ /ip address get [ find interface=$iface ] address ]
:set ip [:pick $ip 0 [:find $ip "/" -1 ] ]
:set ip [:pick $ip 0 [:find $ip "." [:find $ip "."  [:find $ip "."  -1 ] ] ] ]
note there is difference between find and :find

to set default gateway/DNS in DHCP:
/ip dhcp-client
add add-default-route=yes disabled=no interface=<iface> use-peer-dns=yes