Community discussions

 
MKENNEDY
just joined
Topic Author
Posts: 3
Joined: Sun Nov 11, 2018 10:33 pm

DHCP / Network Pool Automation

Sun Nov 11, 2018 10:39 pm

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!
 
crabman
just joined
Posts: 4
Joined: Tue Nov 06, 2018 6:22 am

Re: DHCP / Network Pool Automation

Tue Nov 13, 2018 5:48 am

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
   }
   }
 
 
MKENNEDY
just joined
Topic Author
Posts: 3
Joined: Sun Nov 11, 2018 10:33 pm

Re: DHCP / Network Pool Automation

Tue Nov 13, 2018 3:52 pm

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!
 
crabman
just joined
Posts: 4
Joined: Tue Nov 06, 2018 6:22 am

Re: DHCP / Network Pool Automation

Wed Nov 14, 2018 4:47 am

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.
 
MKENNEDY
just joined
Topic Author
Posts: 3
Joined: Sun Nov 11, 2018 10:33 pm

Re: DHCP / Network Pool Automation

Wed Nov 14, 2018 10:39 am

Thanks a lot.

Do you add the script to the lease-script section of the DHCP Server?
 
crabman
just joined
Posts: 4
Joined: Tue Nov 06, 2018 6:22 am

Re: DHCP / Network Pool Automation

Wed Nov 14, 2018 1:29 pm

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.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 3 guests