Community discussions

MikroTik App
 
abbio90
Member Candidate
Member Candidate
Topic Author
Posts: 164
Joined: Fri Aug 27, 2021 9:16 pm
Contact:

Convert IP 1.1.1.1/24 on 1.1.1.0/24

Mon Jan 23, 2023 9:40 pm

Hello everybody. I made a script that I can't get to work. I basically create a variable like this:
:local AddressDHCP [/ip dhcp-client get [find where interface=bridge_LAN] value-name=address]
:local Network [:pick $AddressDHCP 0 [:find $AddressDHCP "/"]]
:put $AddressDHCP
:put $Network
I would like to fetch the ip released in dhcp-client.
example:1.1.1.1/24 , and I would like to create a new variable with the network 1.1.1.0/24
I managed to remove /24 but how do I change 1 to 0 ?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Convert IP 1.1.1.1/24 on 1.1.1.0/24

Mon Jan 23, 2023 10:54 pm

remove also the 1, and add 0...

Wrong description, your problem is how obtain the cidr network starting from one ip-prefix

Probably you want this...
{
:local ipprefix [/ip dhcp-client get [find where interface=bridge_LAN] address]
:local onlyip   [:toip [:pick $ipprefix 0 [:find $ipprefix "/"]]]
:local prefix   [:tonum [:pick $ipprefix ([:find $ipprefix "/"] + 1) [:len $ipprefix]]]
:local Network  "$($onlyip & (~(255.255.255.255>>$prefix)))/$prefix"
:put $Network
}
This convert, for example 185.62.24.78/12 ip prefix to the start of the IP block 185.48.0.0/12
 
abbio90
Member Candidate
Member Candidate
Topic Author
Posts: 164
Joined: Fri Aug 27, 2021 9:16 pm
Contact:

Re: Convert IP 1.1.1.1/24 on 1.1.1.0/24

Thu Feb 16, 2023 6:57 am

Thanks for the reply and sorry for replying only now. I'll try what you recommend

Who is online

Users browsing this forum: EmuAGR and 22 guests