Community discussions

MikroTik App
 
el berto
Member Candidate
Member Candidate
Topic Author
Posts: 211
Joined: Wed Sep 26, 2007 10:53 am

Extract part of IP address

Mon May 30, 2011 7:24 pm

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.
 
crix75
just joined
Posts: 17
Joined: Thu May 13, 2010 4:42 pm

Re: Extract part of IP address

Mon May 30, 2011 7:55 pm

Hi ,
Can you try with PICK

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

Cris
 
petrn
Member Candidate
Member Candidate
Posts: 179
Joined: Thu Jul 29, 2010 3:56 am

Re: Extract part of IP address

Mon May 30, 2011 8:20 pm

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
Petr

Who is online

Users browsing this forum: No registered users and 14 guests