Overview
Working with IP addresses in NQE opens up all kinds of possibilities, but it’s not always clear what tools are available out of the box. I’ve worked with several customers who wanted to do everything from filtering IPv6 neighbors to calculating subnet utilization across thousands of devices—and the good news is, NQE makes a lot of this simpler than you might expect.
In this post, I’m sharing five of my favorite IP address-related techniques that you might not know about, along with tips for using them in your own queries.
1. Use toNumber() to Compare IP Addresses
When you want to compare IP addresses (e.g., sort them, find the lowest one, etc.), you can use toNumber() to convert each address into a numeric value.
Note that this can only be applied to an IPv4 address.
toNumber(10.1.2.3) // Converts to an integer based on its position in the full IPv4 range
This is useful for identifying router IDs or evaluating address ranges, especially when you don’t know in advance how the addresses are assigned.
2. Match Both IPv4 and IPv6 Without Duplicating Logic
NQE pattern matching returns both IPv4 and IPv6 as the ipAddress type, even though you can still use specific ipv4Address or ipv6Address filters if needed. That means if you're writing a query to find BGP neighbors, for example, you can unify them into a single result.
I used this approach for Dell devices where BGP data wasn't modeled directly. Instead, I pulled peer addresses from CLI output and grouped both v4 and v6 together using a shared type.
3. Calculate Network Addresses with networkAddress()
If you need to calculate the network portion of a subnet, use networkAddress() with an IP and mask or CIDR notation:
networkAddress(10.1.2.3, 255.255.255.0)
// or
networkAddress(10.1.2.3/24)
This is great for subnet summarization and mapping out address spaces in larger queries.
4. Leverage getL3Interfaces() to Avoid Manual Traversal
Instead of manually iterating through route, vlan, loopback, and tunnel interfaces to find IPs, import the interface utilities from Forward Librabry and use the getL3Interfaces() utility to pull them all at once. This simplifies your code and ensures consistency.
import "@fwd/L3/Interface Utilities";
foreach device in network.devices
foreach iface in getL3Interfaces(device)
select iface.ipAddresses
Behind the scenes, it handles the nesting and various types, saving you a ton of manual effort.
5. Evaluate Subnets Without Doing Math
Want to know if an IP belongs to a subnet? Or get the broadcast address? NQE makes it easy without doing bit math yourself. Built-in functions handle these checks efficiently:
- networkAddress() for getting the network
- broadcastAddress() to calculate the broadcast IP
- ipInSubnet(ip, subnet) to check membership
These are especially helpful in compliance queries or when trying to flag misconfigured devices.
In Conclusion..
Whether you're hunting for unused subnets or just trying to make IP output cleaner, these built-in NQE features save time and reduce complexity. If you're already using NQE for device or configuration analysis, chances are you’re closer than you think to using these tricks.
Have a trick of your own? Share it with the community—I'd love to see what others are doing with IP data in NQE.