Community discussions

MikroTik App
 
millenium7
Member Candidate
Member Candidate
Topic Author
Posts: 263
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
Long time Member
Long time Member
Posts: 504
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".
Manage RouterOS scripts and extend your devices' functionality: RouterOS Scripts
 
millenium7
Member Candidate
Member Candidate
Topic Author
Posts: 263
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
Long time Member
Long time Member
Posts: 504
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.
Manage RouterOS scripts and extend your devices' functionality: RouterOS Scripts

Who is online

Users browsing this forum: No registered users and 64 guests