C# API - Delete DHCP Lease

Hello,

I’m using the C# library here: http://wiki.mikrotik.com/wiki/API_in_C_Sharp
I’m trying to delete a lease from the DHCP server. I can get a list of leases using:

mikrotik.Send(“/ip/dhcp-server/lease/print”);

from the command line I get a list with the first column # and then consecutive numbers for each lease. I don’t get that from the API, so I don’t know exactly what to send with the following command:

mikrotik.Send(“/ip/dhcp-server/lease/remove ”);

I have the following code looking up the entry by MAC address:

mikrotik.Send(“/ip/dhcp-server/lease/print”);
mikrotik.Send(“where mac-address=00:19:B9:5E:17:0E”, true);

and I get the following response:

re=.id=*618B=address=ether5 Auburn 2.4Mhz West Sector 10.25.2.2=mac-address=00:19:B9:5E:17:0E=rate-limit=2M/512k 3m/2m=status=bound=expires-after=2d21:25:47=last-seen=20m26s=active-address=10.25.20.3=active-mac-address=00:19:B9:5E:17:0E=active-client-id=1:0:19:b9:5e:17:e=active-server=Auburn 900 South=host-name=lcs-lp-c2d=radius=false=dynamic=false=blocked=false=disabled=false=comment="

I tried parsing out the id portion (.id=*61bB) but that doesn’t work when passing it to the remove. Any ideas?

Robert Lewis

you are getting response of print command

and ‘where’ clause from CLI is not supproted by API, same as ‘find’

look here how that should be done in API
http://wiki.mikrotik.com/wiki/API#Queries

you are getting response of print command
and ‘where’ clause from CLI is not supproted by API, same as ‘find’
look here how that should be done in API
http://wiki.mikrotik.com/wiki/API#Queries

UPDATE:
The following does give me an “!done” response, but does NOT delete the lease:
mikrotik.send(“/ip/dhcp-server/lease/remove “);
mikrotik.send(”?=mac-address=”, true);


Ok, I understand that “query words” need to be used. From the prompt, the only way to remove a lease is to use the generated number listed next to the print command. I used the following:
mikrotik.send(“/ip/dhcp-server/lease/remove “);
mikrotik.send(”?mac-address=”, true);

and I receive a “!trap=message=no such command”

Since the terminal gives me no option but an generated number next to each entry, how do I know what query to pass to this to remove the lease that I want to remove?

Robert

P.S. I thought the forum was supposed to email me when a reply was posted. That’s why I didn’t respond right away. Thanks for the help! :slight_smile:

Any update for this? I need to delete or disable a lease but it doesnt work

You need to make a “print” request that uses query words, extract the ID out of the reply, and plug it into the “remove” command.