Skip to main content

How would one replicate the OneIP table with NQE, including info such as IP address, MAC address, vendor, switch name and switch port?

Hi @alineamorim ,

Great question. We will add a query for this to Forward Library in an upcoming release. In the meantime, here is a query you can use to provide this information. 

 

/**
* @intent Finds IP addresses and subnets on interfaces and hosts.
* @description Similar to IP Inventory query, but is limited to interfaces and
* subnets, and also takes no parameters.
*
* Includes the following columns:
* Subnet: The subnet found
* Address Type: One of IPv4 or IPv6
* Source Type: One of Interface, Host.
* MAC: MAC address associated with the IP, if any.
* Device: The device on which the subnet is found.
*/

import "@fwd/L3/IpAddressUtils";
import "@fwd/L3/Interface Utilities";

isIPv4(a) = isPresent(patternMatch(toString(a), `{ipv4Subnet}`));

addressType(a) = if isIPv4(a) then "IPv4" else "IPv6";

getIpSubnets(addresses) =
foreach addr in addresses
select ipSubnet(addr.ip, addr.prefixLength);

getInterfaceIps(device) =
foreach l3Iface in getL3Interfaces(device)
let ipv4Records = getIpv4Ips(device, l3Iface)
let ipv6Records = getIpv6Ips(device, l3Iface)
foreach record in ipv4Records + ipv6Records
select record;

getIpv4Ips(device, l3Iface) =
foreach subnet in getIpSubnets(l3Iface.ipv4.addresses)
select {
Subnet: subnet,
"Address Type": "IPv4",
"Source Type": "Interface",
Source: l3Iface.name,
MAC: null : MacAddress,
Device: device.name,
Interfaces: sl3Iface.name],
Vlans: stoString(l3Iface.vlan)],
Vendor: device.platform.vendor
};

getIpv6Ips(device, l3Iface) =
foreach subnet in getIpSubnets(l3Iface.ipv6.addresses)
select {
Subnet: subnet,
"Address Type": "IPv6",
"Source Type": "Interface",
Source: l3Iface.name,
MAC: null : MacAddress,
Device: device.name,
Interfaces: sl3Iface.name],
Vlans: stoString(l3Iface.vlan)],
Vendor: device.platform.vendor
};

formatVlanRange(range) =
join("-", distinct(ctoString(range.from), toString(range.to)]));

getHosts(device) =
foreach host in device.hosts
foreach subnet in host.addresses
select {
Subnet: subnet,
"Address Type": addressType(subnet),
"Source Type": "Host",
Source: host.name,
MAC: host.macAddress,
Device: device.name,
Interfaces: host.interfaces,
Vlans: (foreach range in host.vlans
select formatVlanRange(range)),
Vendor: device.platform.vendor
};

foreach device in network.devices
foreach ipRecord in getInterfaceIps(device) + getHosts(device)
select ipRecord

 


Reply