THE GAME HAS CHANGED

Introducing Infoblox Universal DDI ManagementTM

Watch the launch to discover the new era of management for critical network services. Watch Now

API & Integration, DevOps,NetOps,SecOps

Reply

IP Address, Subnet, Default Gateway, and VLAN on Single Line

New Member
Posts: 2
3252     0

I'm looking to use the API to output a single line with the following information: an endpoint's IP address, the network's subnet mask or CIDR, the network's default gateway, and the VLAN associated with the subnet.  The input for this would be the endpoint's IP address.  

 

So far, I know how to get the network address and CIDR as well as the VLAN.  However, I'm not sure how to format the output so that all of the desired items are on a single output line.  

 

The two curl commands I have do get me the VLAN ID assocated with the endpoint IP address, however these are two manual steps whereby the output of the first one is needed as input to the next one (network information, specifically).  Below are the two curl commands, sanitized. 

 

In this command I enter the endpoint IP address:

 curl -k -u <username>:<password> -X GET https://<Infoblox_Grid_Member_IP>/wapi/v2.11.2/search?address=<IP_Address_of_Endpoint>1&_return_as_object=1

 

For the command below, I enter the "network/ZG5..." information, including the network address and CIDR that were output from the command above.  This command outputs the VLAN ID:
curl -k -u admin:infoblox -X GET http://<Infoblox_Grid_Member_IP>/wapi/v2.11.2/vlan?assigned_to=network/ZG5zLm5ldHdvcmskMTcyLjI0LjEyMC4xNi8yOC8w:<network_address_and_CIDR>/default&_return_fields%2b=id

 

In addition to these, I need to get the default gateway, which is expected to be the network address + 1.  Could that be done with built-in arithmetic?  

 

Is my desired single-line output something that can be retrieved from a command line script?  Otherwise, would it require more specialized programming knowledge?

Re: IP Address, Subnet, Default Gateway, and VLAN on Single Line

[ Edited ]
Superuser
Posts: 81
3253     0

Hello,

 

I couldn't find a direct call to yield all fields in the result, per your requirement. But I've written this short python script which will get you the result directly in a single execution. It takes Grid Master IP, username, password & IP address to be looked up as inputs. Here's a sample input/output :

 

terminal-alman:# python3.6 get_ip_vlan_gateway_mask.py

Grid Master IP:192.168.29.110
Enter user name:admin
Password:infoblox
IP Address of End Point to be retrieved:10.1.8.8


***ENDPOINT-RESULTS***

IP_ADDRESS:10.1.8.8
NETWORK_ADDRESS:10.1.8.0
CIDR:22
DEFAULT_GATEWAY:10.1.8.1
VLAN_ID:7

Here's the code below. You may need to make some adjustments to the WAPI version etc based on your needs.

 

import urllib3
import requests
import json
import ipaddress

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

grid_master=input("Grid Master IP:")
user_name=input("Enter user name:")
password=input("Password:")
end_point_ip=input("IP Address of End Point to be retrieved:")
vlan_value=""

base_url='https://'+grid_master+'/wapi/v2.10.1/'
get_reference_response=json.loads(requests.get(url=base_url+'search?address='+end_point_ip+'&_return_as_object=1', headers={'content-type': 'application/json'}, auth=(user_name,password), verify=False).content)
result_filter=get_reference_response.get("result")

for value_network_finder in result_filter:
     network_ref=value_network_finder.get("_ref")
     if "network" in network_ref:
          network_ref_catch=network_ref
          network_find_temp=network_ref_catch.split(":",1)[1]
          network_find=network_find_temp.split("/",1)[0]
          cidr=network_find_temp.split("/",2)[1]
          break

get_vlan_network=json.loads(requests.get(url=base_url+network_ref_catch+'?_return_fields=vlans', headers={'content-type': 'application/json'}, auth=(user_name,password), verify=False).content)

result_vlan=get_vlan_network.get("vlans")
for vlan_finder in result_vlan:
     vlan_value=vlan_finder.get("id")

if vlan_value=="":
     vlan_value="NO VLAN FOUND FOR ASSOCIATED SUBNET"
print(f"\n\n***ENDPOINT-RESULTS***\n\nIP_ADDRESS:{end_point_ip}\nNETWORK_ADDRESS:{network_find}\nCIDR:{cidr}\nDEFAULT_GATEWAY:{ipaddress.IPv4Address(network_find)+1}\nVLAN_ID:{vlan_value}")


Hope this helps. Good luck

 

Best regards,

 

Re: IP Address, Subnet, Default Gateway, and VLAN on Single Line

New Member
Posts: 2
3253     0

Thank you, Mohammed, for putting this together for us.  Kudos to you, Sir!  

 

I haven't run this yet successfully, as I'm working through installing the "urllib3" module.

Showing results for 
Search instead for 
Did you mean: 

Recommended for You