- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Test if an IP address is in a DHCP address range via WAPI?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2021 05:00 PM
Trying to figure this one out in Javascript, but I'll take anything. Can someone help?
Solved! Go to Solution.
Re: Test if an IP address is in a DHCP address range via WAPI?
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2021 01:36 PM - edited 06-27-2023 01:45 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2021 01:43 PM
Thanks! I'll give it a try.
Re: Test if an IP address is in a DHCP address range via WAPI?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2021 04:10 PM
Works great! Thanks.