Filtering MikroTik Devices by IP Address Instead of Vendor

Started by nichky, March 11, 2026, 07:08:32 AM

Previous topic - Next topic

nichky

Hi

I'm currently using the following condition to collect all MikroTik devices:

return $node->vendor == "MikroTik";

Is there any way to perform this per IP address instead?

Alex Kirhenshtein

#1
$node.ipAddr (string)

or $node.ipAddress (instance of InetAddress): https://netxms.org/documentation/nxsl-latest/#class-inetaddress

nichky

$subnet = InetAddress("x.y.z.0")
$mask = 24

if ($node.ipAddress.isInSubnet($subnet, $mask)) {
    return 1;  // match
} else {
    return 0;  // no match
}



I got this, but it's not working. Can you please modify it?

Filipp Sudanov

First of all two first lines should end with ; char.
There is no isInSubnet() method on InetAddress class, but there is contains() method on subnet, so we should go opposite way and check it on the subnet, there's an example here: https://netxms.org/documentation/nxsl-latest/#_instance_methods_18
So, modifying your code:

subnetObject = InetAddress("192.168.56.0", 24);

if (subnetObject.contains($node.ipAddress)) {
    return 1;  // match
} else {
    return 0;  // no match
}

Victor Kirhenshtein

And just for completeness, script above can be simplified to
return InetAddress("192.168.56.0", 24).contains($node.ipAddress);