Skip to content

Querying, Adding, Updating and Deleting Records

Ben Thompson edited this page Nov 11, 2017 · 7 revisions

Querying records

Record sets

Most records come in sets, like /ip/arp. To get a list of all of all records in a set, simply:

var records = link.Ip.Arp.Query();

You can refine the query to return only records matching a particular filter. Here's an example to list all ARP records associated with 1.1.1.1:

var arps = link.Ip.Arp.Query(
    new QueryFilter(nameof(IpArp.Address), QueryOperationType.Equal, "1.1.1.1" )
    // ... as many filters as you'd like
);

In the above example, we used an Equal filter. You can also use GreaterThan and LessThan.

Furthermore, you can request only certain properties to be returned to further save bandwidth and improve response speeds:

var arps = link.Ip.Arp.Query(
    new string[] { // Include as many fields are desired
        nameof(IpArp.Id),
        nameof(IpArp.MacAddress)
    },
    new QueryFilter[] {
        new QueryFilter(nameof(IpArp.Address), QueryOperationType.Equal, "1.1.1.1" )
    }
);

Single records

A few records are loners, and there's only ever one of them. For example, consider \ip\dhcp-server\config. You can get these by:

var config = link.Ip.DhcpServer.Config.Get();

If you're only interested in certain properties, you can limit the ones returned like so:

var config = link.Ip.DhcpServer.Config.Get(new string[]{
    nameof(IpDhcpServer.StoreLeasesDisk);
});

Adding records

You can create a new record by:

link.Ip.Arp.Add(new IpArp() {
    Address = "1.1.1.1",
    MacAddress = "00:00:00:00:00:01"
});

Updating records

// ... get a ARP record via a Query
arp.Address = "2.2.2.2";
link.Ip.Arp.Update(arp);

Deleting records

// ... get a ARP record via a Query
arp.Address = "2.2.2.2";
link.Ip.Arp.Update(arp);

Moving records

If the record set is ordered, like /ip/firewall/filter and /ip/firewall/nat, then you can change the order of records. The following moves recordB before recordA.

link.Ip.Firewall.Filter.Move(recordA, recordB);

The following moves recordB and recordC before recordA:

link.Ip.Firewall.Filter.Move(recordA, recordB, recordC);

The following moves recordB to the end:

link.Ip.Firewall.Filter.Move(null, recordB);

Clone this wiki locally