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

Test if an IP address is in a DHCP address range via WAPI?

New Member
Posts: 5
3853     0

Trying to figure this one out in Javascript, but I'll take anything.  Can someone help?

Re: Test if an IP address is in a DHCP address range via WAPI?

[ Edited ]
Superuser
Posts: 81
3854     0

Hello Swarner,

 

Here's a script in python to get what you're looking for. It takes an IP address as input(just as plain string). I hope this would be of help.

 

#Find the network ID & usage type of a specific IPv4Address
   
import requests
import urllib3
import json
from os import system, name

def clear():
    if name == 'nt':
        _ = system('cls')
    else:
        _ = system('clear')
  

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

gm_ip= input("\n\nEnter Grid master IP :")
type(gm_ip)
gm_user=input("\nEnter user name :")
type(gm_user)
gm_password=input("\nEnter password :")
type(gm_password) 

continue_check="y"

while continue_check=='y':
  clear()
  ip_address=input("\nEnter the IP address to be checked :")
  type(ip_address)
  urL = 'https://'+gm_ip+'/wapi/v2.7/ipv4address?ip_address='+ip_address
  response = requests.get(urL, auth=(gm_user, gm_password), verify=False)
  mid_value=response.content
  response_native = json.loads(mid_value)

  if(response.status_code==200):
    for resp in response_native:
      network_id= resp.get("network")
      print("\n\n"+str(ip_address)+" belongs to : " + str(network_id)+" network.")
      type_of_usage = ["FA", "DHCP_RANGE", "RESERVED"]
      if any(x in resp.get("types") for x in type_of_usage):       
        if "DHCP_RANGE" in resp.get("types"):
          print("\nThe address "+str(ip_address)+" is a part of the DHCP range for "+str(network_id)+" network.")
        if "FA" in resp.get("types"):
          print("\n"+str(ip_address)+" is binded to "+str(resp.get("mac_address"))+" as a DHCP Fixed address.")
        if "RESERVATION" in resp.get("types"):
          print("\n"+str(ip_address)+" is a DHCP RESERVED address.")    
      else:
        print("\n"+str(ip_address)+" doesn't appear to be in use as a Range/Fixed address or Reservation object.")
 
  else:
    print("\n\nHTTP response code : " + str(response.status_code)+". It appears that the IPv4 object doesn't exist in any of the configured grid networks..")
  continue_check= input("\n\nTo try another IP, hit 'y'. Else anything to escape :")
  type(continue_check)

Please be careful about the intendations during copy/paste.

 

Best regards,

 

Re: Test if an IP address is in a DHCP address range via WAPI?

New Member
Posts: 5
3854     0

Thanks!  I'll give it a try.

Re: Test if an IP address is in a DHCP address range via WAPI?

New Member
Posts: 5
3854     0

Works great!  Thanks.

Showing results for 
Search instead for 
Did you mean: 

Recommended for You

NIOS 8.6.3 – What’s New in DDI