DHCP / Network Pool Automation

Hi all
I’m brand new to Mikrotik and now very little about it so please excuse any dump questions - and assistance will be greatly appreciated!

What I need to get done:
Basically what I need to achieve is, to run a script on my DHCP Server (MikroTIk) and if it detects android or iphone in the hostname, it should assign an IP in a network pool that I created.

What I have at this stage:

:foreach i in=[/ip dhcp-server lease find] do={
:local hostname [/ip dhcp-server lease get $i host-name]

:if ($hostname~“ipad|iPad|android|Android|iphone|iPhone”) do={
:local ipaddr [/ip dhcp-server lease get $i address]
I NEED THE CORRECT COMMAND HERE, AS FAR AS I KNOW
}
}

Thanks so much!

i got same problem with you bro, hope this could help you. it gives what i need, make static and set ip address pool named HP

:foreach i in=[/ip dhcp-server lease find dynamic=yes]  do={
   :local DVCHOST [/ip dhcp-server lease get $i host-name];

   :if ($DVCHOST~"ASUS|wt88|Redm|redm") do={

   /ip dhcp-server lease make-static [/ip dhcp-server lease find where host-name="$DVCHOST"]

   /ip dhcp-server lease set [/ip dhcp-server lease find where host-name="$DVCHOST"] address=HP
   }
   }

Thanks a lot for the reply!

Just to understand (And sorry for the stupid questions).

Does this look for a hostname that contains “ASUS|wt88|Redm|redm” and assigns it to the HP IP Pool?

Is there a way to assign it to a network instead of a pool? I only have one DHCP IP Pool at the moment and only want one.

Appreciate!

Yes it’s in my network, just make ip pool that you want, name it and set that pool for hp.if you have more brand name let says memephone,oppo etc just add the name into list as $DVCHOST.

Thanks a lot.

Do you add the script to the lease-script section of the DHCP Server?

Yep, it will run on dhcp lease script just give it a try with 1 brand of mobile phone. You will know what the script do.