Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search for a single IP address via API #2194

Closed
maznu opened this issue Jun 25, 2018 · 7 comments
Closed

search for a single IP address via API #2194

maznu opened this issue Jun 25, 2018 · 7 comments

Comments

@maznu
Copy link

maznu commented 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.

@maznu
Copy link
Author

maznu commented Jun 25, 2018

Submitting a simple 12-line patch: #2195

@dimecho
Copy link

dimecho commented Jun 26, 2018

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

@maznu
Copy link
Author

maznu commented 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") :-(

@dimecho
Copy link

dimecho commented Jun 27, 2018

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

@DanSheps
Copy link
Member

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

@jeremystretch
Copy link
Member

jeremystretch commented 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.

@maznu
Copy link
Author

maznu commented 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?

@lock lock bot locked as resolved and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants