search for a single IP address via API #1810

Closed
opened 2025-12-29 17:19:19 +01:00 by adam · 7 comments
Owner

Originally created by @maznu on GitHub (Jun 25, 2018).

Issue type

[ ] Feature request
[X] Bug report
[ ] Documentation

  • NetBox version: bleeding edge

Description

I want to find out whether an IP address exists in NetBox via the API. Currently it doesn't seem possible to do that, because the only searches available either:

  • match by string, which the needs client-side filtering because 192.0.2.1 matches 192.0.2.100 etc
  • query by parent, but that can't query an IPv4 /32 or IPv6 /128 (no results returned), so instead you have to query /31 or /127 and again filter client-side for the address you actually wanted

I propose adding ?address=192.0.2.1 as a query endpoint.

Originally created by @maznu on GitHub (Jun 25, 2018). ### Issue type [ ] Feature request <!-- An enhancement of existing functionality --> [X] Bug report <!-- Unexpected or erroneous behavior --> [ ] Documentation <!-- A modification to the documentation --> * NetBox version: bleeding edge ### Description I want to find out whether an IP address exists in NetBox via the API. Currently it doesn't seem possible to do that, because the only searches available either: * match by string, which the needs client-side filtering because 192.0.2.1 matches 192.0.2.100 etc * query by parent, but that can't query an IPv4 /32 or IPv6 /128 (no results returned), so instead you have to query /31 or /127 and again filter client-side for the address you actually wanted I propose adding `?address=192.0.2.1` as a query endpoint.
adam closed this issue 2025-12-29 17:19:19 +01:00
Author
Owner

@maznu commented on GitHub (Jun 25, 2018):

Submitting a simple 12-line patch: https://github.com/digitalocean/netbox/pull/2195

@maznu commented on GitHub (Jun 25, 2018): Submitting a simple 12-line patch: https://github.com/digitalocean/netbox/pull/2195
Author
Owner

@dimecho commented on GitHub (Jun 27, 2018):

/api/ipam/ip-addresses/?q=192.0.2.1

@dimecho commented on GitHub (Jun 27, 2018): `/api/ipam/ip-addresses/?q=192.0.2.1`
Author
Owner

@maznu commented on GitHub (Jun 27, 2018):

@poofik that will return 192.0.2.100 and about 109 other addresses, and anything that has 192.0.2.1 in the description (e.g. "new address replacing 192.0.2.199") :-(

@maznu commented on GitHub (Jun 27, 2018): @poofik that will return 192.0.2.100 and about 109 other addresses, and anything that has 192.0.2.1 in the description (e.g. "new address replacing 192.0.2.199") :-(
Author
Owner

@dimecho commented on GitHub (Jun 27, 2018):

put a slash for subnet and cut it off /api/ipam/ip-addresses/?q=192.0.2.1/

@dimecho commented on GitHub (Jun 27, 2018): put a slash for subnet and cut it off `/api/ipam/ip-addresses/?q=192.0.2.1/`
Author
Owner

@DanSheps commented on GitHub (Jun 27, 2018):

poofik is correct, there is a way to get exact prefixes.

@DanSheps commented on GitHub (Jun 27, 2018): poofik is correct, there is a way to get exact prefixes.
Author
Owner

@jeremystretch commented on GitHub (Jun 29, 2018):

While @poofik's approach work, it's a hack. I don't see a reason not expose the address field itself.

It's important to note that the address field includes the IP address and its mask. It seems the most practical approach would be to match any IP address if the mask is omitted. That is, ?address=192.0.2.1 would return IPs 192.0.2.1/24 and 192.0.2.1/32, whereas ?address=192.0.2.1/24 would return only the former.

@jeremystretch commented on GitHub (Jun 29, 2018): While @poofik's approach work, it's a hack. I don't see a reason not expose the `address` field itself. It's important to note that the address field includes the IP address _and_ its mask. It seems the most practical approach would be to match any IP address if the mask is omitted. That is, `?address=192.0.2.1` would return IPs 192.0.2.1/24 and 192.0.2.1/32, whereas `?address=192.0.2.1/24` would return only the former.
Author
Owner

@maznu commented on GitHub (Jun 29, 2018):

Thanks, @jeremystretch! I didn't like the hack because q=1.2.3.4/ will still return 11.2.3.4 and 21.2.3.4 etc?

@maznu commented on GitHub (Jun 29, 2018): Thanks, @jeremystretch! I didn't like the hack because q=1.2.3.4/ will still return 11.2.3.4 and 21.2.3.4 etc?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1810