Reply
Highlighted

Network hierarchy

Authority
Posts: 36
3434     0

Is there a way to obtain the entire network hiearchy if a network is provided?

 

Say, the hierarchy is as follows-

1.0.0.0/7 -> 1.0.0.0/8 -> 1.1.0.0/16 -> 1.1.1.0/24

 

If we supply 1.1.1.0/24 as the parameter, is it possible via WAPI (preferably) or PAPI to obtain all the network containers in that hierarchy?

Re: Network hierarchy

AMani Community Manager
Community Manager
Posts: 28
3435     0

Hello,

 

The following community topic seems similar to your request. Can you check if this is applicable to your scenario?

 

https://community.infoblox.com/t5/Best-Practices/CSV-export-of-address-information-for-entire-networ...

 

Regards,

 

Re: Network hierarchy

Authority
Posts: 36
3435     0

Thank you for replying, however, I need it the other way. In the solution you cited, it goes from top-down level, meaning, if a container is given, we find the other containers or networks inside it.

 

What I require is, if a network is provided, all the containers on top of it.

Re: Network hierarchy

pmeyerson
Techie
Posts: 12
3435     0

check the network_container field for your network object. Sounds like you should be able to use that to navigate up the hierarchy.

Re: Network hierarchy

Authority
Posts: 36
3435     0

You're correct. The solution you mentioned is perfect but it'll only give you the immediate container of the subnet. However, I wanted a solution where I didn't have to create a loop in case there are multiple network containers.

Re: Network hierarchy

[ Edited ]
Authority
Posts: 19
3435     0

Here is a short Python program to trace the hierarchy of any IP address from parent Network Container to topmost Container:

 

## Import the required Python modules
import json
import requests
import netaddr

requests.packages.urllib3.disable_warnings()

## Collect containers from Grid using API
url = "https://infoblox.example.com/wapi/v2.6.1/networkcontainer?_return_as_object=1"
response = requests.request("GET",url,auth=('admin','infoblox'),verify=False)

## Test request success status
#print(response)

## Convert data to json readable
data = json.loads(response.text)

while True:
    ## Input argument
    ipAddr=input('Enter IP address (without /CIDR) to check hierarchy (Input e to exit): ')

    ## Exit plot
    if (ipAddr=='e'):
        break
        
    ## Match input against collected networks 
    for container in data['result']:
        try:
            if (ipAddr in netaddr.IPNetwork(container['network'])):
                print(container['network'])
        except netaddr.core.AddrFormatError:
            print('Invalid input')
            break
print('END')

Test case

Containers in Grid :

 

2.0.0.0/24
1.1.1.0/24
1.1.2.0/24
1.1.0.0/16
1.5.0.0/16
1.0.7.0/24
1.0.0.0/8

 

Below is a sample output :

 

Enter IP address (without /CIDR) to check hierarchy (Input e to exit): Lorem
Invalid input
Enter IP address (without /CIDR) to check hierarchy (Input e to exit): 1111.23243.23423.234234
Invalid input
Enter IP address (without /CIDR) to check hierarchy (Input e to exit): 1.1.1.0
1.1.1.0/24
1.1.0.0/16
1.0.0.0/8
Enter IP address (without /CIDR) to check hierarchy (Input e to exit): 1.1.1.45
1.1.1.0/24
1.1.0.0/16
1.0.0.0/8
Enter IP address (without /CIDR) to check hierarchy (Input e to exit): 1.1.4.0
1.1.0.0/16
1.0.0.0/8
Enter IP address (without /CIDR) to check hierarchy (Input e to exit): 2.3.0.0
Enter IP address (without /CIDR) to check hierarchy (Input e to exit): 2.0.0.55
2.0.0.0/24
Enter IP address (without /CIDR) to check hierarchy (Input e to exit): e
END

 

Note that when the input IP address does not match any Container, no matches are returned.

 

Re: Network hierarchy

Authority
Posts: 36
3435     0

This is a really good solution but I'm not using python. I can work with either php or perl. I was looking for something more like an API (WAPI or PAPI) that will give the hierarchy directly.

Showing results for 
Search instead for 
Do you mean 

Recommended for You

Businesses are investing heavily into securing company resources from cyber-attacks form cybercrimin