Skip to content

Routing Search

In version 6.9.0 of the ipfabric Python SDK a new ipf_route_search CLI tool was added. After installing the package it can be run from the command line.

Requirements

Required environment variables exported (IPF_URL and IPF_TOKEN or IPF_USERNAME & IPF_PASSWORD) or a .env file located in the current working directory or your home directory.

Installing rich will enable prettier output (pip install rich or pip install ipfabric[cli]).

Documentation

IPF Route Search Help
# ipf_route_search -h
usage: ipf_route_search.cmd [-h] [-o OPERATOR] [-d] [-n] [-c] [-s SNAPSHOT] [-v] [-j] [-R] address

Search IPv4 or IPv6 Route tables for an Address or Subnet.

positional arguments:
  address               IPv4 or IPv6 Address/CIDR to search for.

optional arguments:
  -h, --help            show this help message and exit
  -o OPERATOR, --operator OPERATOR
                        Default 'eq'
  -d, --default-route   Include "0.0.0.0/0" routes.
  -n, --next-hop        Search Next Hop IP instead of Route.
  -c, --count           Print count of rows instead of the actual data.
  -s SNAPSHOT, --snapshot SNAPSHOT
                        Snapshot to use which can be a UUID or one of ['last', 'prev', 'lastLocked']with or without `$` for *nix compatability.
  -v, --verbose         Verbose output will enable debugging and print all tables even if no data.
  -j, --json            Enable JSON output which will also print all tables even if no data.
  -R, --rich-disable    Disable rich formatting if installed. Useful for sending JSON output to jq.
Valid Operators
IPv4 and IPv6 Route or Next Hop IP:
    `=|eq`: Route (CIDR) or Next Hop IP exactly matches.
    `IP|ip`: IP is contained within Routed subnet or Next Hop IP matches.

IPv4 and IPv6 Next Hop IP:
    `cidr|CIDR`: Next Hop IP is contained within subnet.

IPv4 Route CIDR Searching:
    `>|gt`: CIDR is strict supernet (10.0.0.0/24 -> 10.0.0.0/[8..23], 0.0.0.0/0)
    `>=|gte`: CIDR is supernet (10.0.0.0/24 -> 10.0.0.0/[8..24], 0.0.0.0/0)
    `<|lt`: CIDR is strict subnet (10.0.0.0/24 -> 10.0.0.0/[25..32])
    `<|lte`: CIDR is subnet (10.0.0.0/24 -> 10.0.0.0/[24..32])
    `@|sect`: CIDR overlaps (10.0.0.0/24 -> 10.0.0.0/[8..32], 0.0.0.0/0)
    `!@|nsect`: CIDR does not overlap (10.0.0.0/24 -> 10.1.0.0/24)

Usage

Find all routes equal to '1.23.4.5/32'.
# ipf_route_search 1.23.4.5/32

Technology  Routing  Routes: "Cumulative IPv4 routing table"
https://demo1.us.ipfabric.io/technology/routing/routes?options=%7B%22filters%22%3A%7B%22and%22%3A%5B%7B%22network%22%3A%5B%22eq%22%2C%221.23.4.5%2F32%22%5D%7D%2C%7B%22network%22%3A%5B%22neq%22%2C%220.0.0.0%2F0%22%5D%7D%5D%7D%7D
[
    {
        "vrf": "",
        "prefix": 32,
        "id": "1830209184",
        "siteName": "HWLAB",
        "network": "1.23.4.5/32",
        "nhLowestAge": null,
        "sn": "FGL2748L50H",
        "nhLowestMetric": null,
        "protocol": "S",
        "nhCount": 1,
        "hostname": "Cisco-NFVIS-1",
        "nexthop": [
            {
                "ad": null,
                "age": null,
                "intName": "MGMT",
                "ip": "10.64.128.1",
                "labels": null,
                "metric": null,
                "oid": null,
                "vni": null,
                "vrfLeak": null,
                "vtepIp": null
            }
        ]
    }
]
Find all routes equal to '10.81.254.0/28'.
# ipf_route_search 10.81.254.0/28 -c        

No routes found.
Find all routes less than or equal to '10.81.254.0/28' (/28, /29, /30, ...).
# ipf_route_search 10.81.254.0/28 -c -o lte

Technology  Routing  Routes: "Cumulative IPv4 routing table": 312
https://demo1.us.ipfabric.io/technology/routing/routes?options=%7B%22filters%22%3A%7B%22and%22%3A%5B%7B%22network%22%3A%5B%22lte%22%2C%2210.81.254.0%2F28%22%5D%7D%2C%7B%22network%22%3A%5B%22neq%22%2C%220.0.0.0%2F0%22%5D%7D%5D%7D%7D
Find all routes greater than or equal to '10.81.254.0/28' (..., /26, /27, /28).
# ipf_route_search 10.81.254.0/28 -c -o gte

Technology  Routing  Routes: "Cumulative IPv4 routing table": 40
https://demo1.us.ipfabric.io/technology/routing/routes?options=%7B%22filters%22%3A%7B%22and%22%3A%5B%7B%22network%22%3A%5B%22gte%22%2C%2210.81.254.0%2F28%22%5D%7D%2C%7B%22network%22%3A%5B%22neq%22%2C%220.0.0.0%2F0%22%5D%7D%5D%7D%7D
Find all routes overlapping '10.81.254.0/28' (..., /26, /27, /28, /29, /30, ...).
# ipf_route_search 10.81.254.0/28 -c -o sect

Technology  Routing  Routes: "Cumulative IPv4 routing table": 352
https://demo1.us.ipfabric.io/technology/routing/routes?options=%7B%22filters%22%3A%7B%22and%22%3A%5B%7B%22network%22%3A%5B%22sect%22%2C%2210.81.254.0%2F28%22%5D%7D%2C%7B%22network%22%3A%5B%22neq%22%2C%220.0.0.0%2F0%22%5D%7D%5D%7D%7D
Find all routes overlapping '10.81.254.0/28' (..., /26, /27, /28, /29, /30, ...) including '0.0.0.0/0'.
# ipf_route_search 10.81.254.0/28 -c -o sect -d

Technology  Routing  Routes: "Cumulative IPv4 routing table": 530
https://demo1.us.ipfabric.io/technology/routing/routes?options=%7B%22filters%22%3A%7B%22network%22%3A%5B%22sect%22%2C%2210.81.254.0%2F28%22%5D%7D%7D
Find all routes that do not overlap '10.81.254.0/28' (i.e. '192.168.0.0/0').
# ipf_route_search 10.81.254.0/28 -c -o nsect    

Technology  Routing  Routes: "Cumulative IPv4 routing table": 73638
https://demo1.us.ipfabric.io/technology/routing/routes?options=%7B%22filters%22%3A%7B%22and%22%3A%5B%7B%22network%22%3A%5B%22nsect%22%2C%2210.81.254.0%2F28%22%5D%7D%2C%7B%22network%22%3A%5B%22neq%22%2C%220.0.0.0%2F0%22%5D%7D%5D%7D%7D

IPv6 search only supports =|eq or ip|IP operators at this time.

Find IPv6 Routes equal to 'fc00:71:110:ff00::1/128'.
# ipf_route_search fc00:71:110:ff00::1/128     

Technology  Routing  Routes: "Cumulative IPv6 routing table"
https://demo1.us.ipfabric.io/technology/routing/routes/ipv6?options=%7B%22filters%22%3A%7B%22and%22%3A%5B%7B%22network%22%3A%5B%22eq%22%2C%22fc00%3A71%3A110%3Aff00%3A%3A1%2F128%22%5D%7D%2C%7B%22network%22%3A%5B%22neq%22%2C%220.0.0.0%2F0%22%5D%7D%5D%7D%7D
[
    {
        "vrf": "",
        "prefix": 128,
        "id": "1831381876",
        "siteName": "L71",
        "network": "fc00:71:110:ff00::1/128",
        "nhLowestAge": 651600,
        "sn": "FOSVM1HHJXBISQD7/root",
        "nhLowestMetric": null,
        "protocol": "C",
        "nhCount": 1,
        "hostname": "L71FW9/root",
        "nexthop": [
            {
                "ad": null,
                "age": 651600,
                "intName": "sit-1",
                "ip": null,
                "metric": null,
                "vrfLeak": null
            }
        ]
    }
]
Find IPv6 Routes that contains IP 'fc00:71:110:ff00::1'.
# ipf_route_search fc00:71:110:ff00::1 -o ip -c

Technology  Routing  Routes: "Cumulative IPv6 routing table": 1
https://demo1.us.ipfabric.io/technology/routing/routes/ipv6?options=%7B%22filters%22%3A%7B%22and%22%3A%5B%7B%22network%22%3A%5B%22ip%22%2C%22fc00%3A71%3A110%3Aff00%3A%3A1%22%5D%7D%2C%7B%22network%22%3A%5B%22neq%22%2C%22%3A%3A%2F0%22%5D%7D%5D%7D%7D
Find IPv6 Routes that contains IP 'fc00:71:110:ff00::1' including default '::/0'.
# ipf_route_search fc00:71:110:ff00::1 -o ip -c

Technology  Routing  Routes: "Cumulative IPv6 routing table": 3
https://demo1.us.ipfabric.io/technology/routing/routes/ipv6?options=%7B%22filters%22%3A%7B%22network%22%3A%5B%22ip%22%2C%22fc00%3A71%3A110%3Aff00%3A%3A1%22%5D%7D%7D
Find all routes with a Next Hop IP of '10.31.172.114'.
# ipf_route_search 10.31.172.114 -n -c

Technology  Routing  Routes: "Cumulative IPv4 routing table": 22
https://demo1.us.ipfabric.io/technology/routing/routes?options=%7B%22filters%22%3A%7B%22and%22%3A%5B%7B%22nexthop%22%3A%5B%22any%22%2C%22ip%22%2C%22eq%22%2C%2210.31.172.114%22%5D%7D%2C%7B%22network%22%3A%5B%22neq%22%2C%220.0.0.0%2F0%22%5D%7D%5D%7D%7D
Find all routes with a Next Hop IP in '10.31.172.0/24'.
# ipf_route_search 10.31.172.0/24 -n -c -o cidr 

Technology  Routing  Routes: "Cumulative IPv4 routing table": 502
https://demo1.us.ipfabric.io/technology/routing/routes?options=%7B%22filters%22%3A%7B%22and%22%3A%5B%7B%22nexthop%22%3A%5B%22any%22%2C%22ip%22%2C%22cidr%22%2C%2210.31.172.0%2F24%22%5D%7D%2C%7B%22network%22%3A%5B%22neq%22%2C%220.0.0.0%2F0%22%5D%7D%5D%7D%7D
Find all routes with a Next Hop IP in 'fe80::21f:caff:fe08:8035'.
# ipf_route_search fe80::21f:caff:fe08:8035 -n -c

Technology  Routing  Routes: "Cumulative IPv6 routing table": 5
https://demo1.us.ipfabric.io/technology/routing/routes/ipv6?options=%7B%22filters%22%3A%7B%22and%22%3A%5B%7B%22nexthop%22%3A%5B%22any%22%2C%22ip%22%2C%22eq%22%2C%22fe80%3A%3A21f%3Acaff%3Afe08%3A8035%22%5D%7D%2C%7B%22network%22%3A%5B%22neq%22%2C%22%3A%3A%2F0%22%5D%7D%5D%7D%7D

JSON Output

If using JSON output disable rich with the -R|--rich-disable flag prior to sending to jq.

Find IPv4 Routes that overlap '10.81.254.0/28' returning unformatted JSON piping to 'jq'.
# ipf_route_search 10.81.254.0/28 -o sect -d -j -R | jq '.data[0]' 
{
  "vrf": "",
  "prefix": 0,
  "id": "1829938298",
  "siteName": "AWS",
  "network": "0.0.0.0/0",
  "nhLowestAge": null,
  "sn": "nat-0a36a8462da82816f",
  "nhLowestMetric": null,
  "protocol": "S",
  "nhCount": 1,
  "hostname": "pg-nat-A-private",
  "nexthop": [
    {
      "ad": null,
      "age": null,
      "intName": "eni-0ef85997880302d46",
      "ip": null,
      "labels": null,
      "metric": null,
      "oid": "Default route via VPC vpc-064bcd18a618d41cb",
      "vni": null,
      "vrfLeak": null,
      "vtepIp": null
    }
  ]
}