Community discussions

 
bsayre1958
just joined
Topic Author
Posts: 1
Joined: Tue Feb 05, 2019 12:19 am

API to Set DHCP Server Address List

Tue Feb 05, 2019 12:28 am

Hello,

I have a cli command I am trying to push through the API. The ClI command is
/ip dhcp-server lease set [find host-name="Unit8103Mikrotik"] address-lists="noaccess" I have tested this and it works just fine from the cli. My API looks like this

UnitString = "Unit8103Mikrotik"
mk.Send("ip/dhcp-server/lease/set", False)
mk.Send("=host-name=" & UnitString, False)
mk.Send("=address-lists=" & "noaccess", True)

I am getting the "no such command" in response. I have also pulled the .id and used it as =.id= and the id. I have also reordered the push so the 2 and 3rd lines are reversed. I am using the vb.net sample code to effect this. I have been able to pull the print command using this same host-name without a problem. Any help would be appreciated.

Thanks
 
nescafe2002
Long time Member
Long time Member
Posts: 622
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: API to Set DHCP Server Address List

Tue Feb 05, 2019 5:11 pm

The reason you're getting "no such command" is because "ip/dhcp-server/lease/set" is not a valid command.

You're missing the leading "/" => "/ip/dhcp-server/lease/set" is valid :)

Also, you cannot use [ find ] syntax in API. Print with filter to get id, then update by id.

mk.Send("/ip/dhcp-server/lease/print")
mk.Send("=.proplist=.id")
mk.Send("?host-name=" & UnitString, True)

Dim id As String = Nothing

For Each h As String In mk.Read()
    Console.WriteLine(h)

    If h.StartsWith("!re=") Then
        id = h.Substring("!re=.id=".Length)
    End If
Next

If String.IsNullOrEmpty(id) Then Return
    
mk.Send("/ip/dhcp-server/lease/set")
mk.Send("=.id=" & id)
mk.Send("=address-lists=noaccess", True)

For Each h As String In mk.Read()
    Console.WriteLine(h)
Next

Who is online

Users browsing this forum: No registered users and 11 guests