A simple phpIPAM API helper script for finding possible subnets of the given IP address.
-
Create
~/.ipam/token.json
{ "ApiPath": "your-phpipam-api-url", "AppToken": "your-api-token" }
-
Install requirements
# Optional: create and activate virtualenv virtualenv env . env/bin/activate pip install -r requirements.txt
-
To find possible subnets of an IP address
python phpipam_api_helper.py --ip <ip_address>
When running the script the first time, the script makes API request to the phpIPAM to retrieve info of all subnets, then save the data to
~/.ipam/data.json
. So when making subsequent calls, the scripts use the data in this local file instead of making API calls again. -
To enforce making phpIPAM API calls instead of the local copy of IPAM data
python phpipam_api_helper.py --ip <ip_address> --refresh
- To create App ID and token, see https://phpipam.net/api/api_curl_example/
- Test access:
curl -X GET https://<url>/api/<appname>/addresses/tags/ -i --header 'token: <app-token>' --insecure
url_rewrite
is required for API to work. See https://phpipam.net/api-documentation/- See phpipam/phpipam#2624