Community discussions

MikroTik App
 
millenium7
Long time Member
Long time Member
Topic Author
Posts: 539
Joined: Wed Mar 16, 2016 6:12 am

Are special parameters parsed when script ran by DHCP server?

Mon Mar 23, 2020 5:12 am

At the moment I have a 30 line script to ensure only 1 DHCP lease can be active per Remote-ID at a time, the newest lease clears all other entries that have the same Remote-ID (potential issue if a client plugged a switch into their WAN connection instead of a router) but there's currently a bug in the script. Rather than running through it again and trying to debug, the script could be very simple if certain parameters are parsed to it from the DHCP server

At the moment it iterates through every single lease, finds the newest, then purges all others
If parsed parameters can be used then instead I could do it all on 1 line with something like
/ip dhcp-server lease remove [find where remote-id=%8 active-mac-address!=%1]

Where %1 would be the MAC address of the lease that triggered the script, %8 would be the remote-id
Is this supported in the MikroTik world?
 
User avatar
eworm
Forum Guru
Forum Guru
Posts: 1071
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Are special parameters parsed when script ran by DHCP server?

Wed Mar 25, 2020 12:16 am

At the moment I have a 30 line script to ensure only 1 DHCP lease can be active per Remote-ID at a time, the newest lease clears all other entries that have the same Remote-ID (potential issue if a client plugged a switch into their WAN connection instead of a router) but there's currently a bug in the script. Rather than running through it again and trying to debug, the script could be very simple if certain parameters are parsed to it from the DHCP server

At the moment it iterates through every single lease, finds the newest, then purges all others
If parsed parameters can be used then instead I could do it all on 1 line with something like
/ip dhcp-server lease remove [find where remote-id=%8 active-mac-address!=%1]

Where %1 would be the MAC address of the lease that triggered the script, %8 would be the remote-id
Is this supported in the MikroTik world?
There is no property "remote-id". Does client's hostname do the job?
/ ip dhcp-server lease remove [ find where host-name=$"lease-hostname" active-mac-address!=$leaseActMAC ]
See Manual:IP/DHCP Server and search for "lease-script".
 
millenium7
Long time Member
Long time Member
Topic Author
Posts: 539
Joined: Wed Mar 16, 2016 6:12 am

Re: Are special parameters parsed when script ran by DHCP server?

Wed Mar 25, 2020 1:14 am

err yes there is
agent-remote-id and agent-circuit-id are parameters that are injected into DHCP request packets by another inline device, also knows as DHCP Option 82
Both are supported in MikroTik's DHCP server as read-only parameters
 
User avatar
eworm
Forum Guru
Forum Guru
Posts: 1071
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Are special parameters parsed when script ran by DHCP server?

Wed Mar 25, 2020 8:30 am

Well, ok... Did not try to guess the correct name. Just "remote-id" is not available.

You can get that info from $"lease-options". With ($"lease-options"->"82") you get both infos from option 82, surrounded by some binary bits. Looks like you have to parse that yourself.
 
blueknight529
just joined
Posts: 3
Joined: Wed Feb 23, 2022 2:04 pm

Re: Are special parameters parsed when script ran by DHCP server?

Mon Mar 07, 2022 6:39 pm

Did you ever get this script to work?
I am in need of this, and would you be inclined to share?
 
blueknight529
just joined
Posts: 3
Joined: Wed Feb 23, 2022 2:04 pm

Re: Are special parameters parsed when script ran by DHCP server?

Tue Mar 08, 2022 11:41 am

millenium7,
I am in need of this script you mentioned above.
Did you get it to work correctly?
Would you care to share it?

Who is online

Users browsing this forum: No registered users and 22 guests