This task is a follow up to the discussion on Wikidata.
There is no way to query an IP address range in IPv4 routing prefix or IPv6 routing prefix. The string itself, of course, can be queried, but it is impossible to determine if a given IP address exists within the the stored range.
Given the IP address 18.104.22.168 it is impossible to reason that the IP address belongs to Wikimedia Foundation.
During the Anti-Harassment offsite, we discussed many potential improvements to CheckUser. One idea was to provide a reverse IP address lookup as a standalone tool on Toolforge and maybe within the extension itself (see T174553). This would give stewards details about an IP address and help them make sock judgements. Many stewards already use non-free (as in speech) tools for this purpose. The Wikidata community already finds IP ranges as valuable data (given the creation of the two aforementioned properties). It might be wise to utilize this data for the community.
Based on the solution proposed in the discussion, the best solution would be to fix the storage rather than duplicating the data.
Create a new data type that extends from quantity. This new data type would be able to store a single IP address in decimal form, or a range of IP addresses in decimal form. The unit would be set to either http://www.wikidata.org/entity/Q11103 or http://www.wikidata.org/entity/Q2551624 based on what the input is (the URIs should be customizable in config). The UI would display either a single IP address or a CIDR range. The Wikidata-Query-Service would allow querying the field in decimal form, or perhaps a FILTER can be created in the future to convert an IP address to decimal form.
- Duplicate the data in a Wikidata qualifier (the original proposal) or index the data in an external database. This is problematic though, as it requires querying and looping through many (right now thousands, later hundreds of thousands, or even millions) of records and keeping this data up-to-date. It also becomes problematic to filter based on other properties (as you would do with the Wikidata-Query-Service).
- Convert the existing fields to a standard quantity field. This solution does solve the problem, but creates a user experience (UX) problem as editors will need to properly convert an IP range to decimal format. For instance 10.0.0.1/24 would need to be entered as 167772287.5±127.5.