This task is a follow up to the [[ https://www.wikidata.org/wiki/Wikidata:Property_proposal/IP_range_start | discussion ]] on Wikidata.
**Problem**
There is no way to query an IP address range in [[ https://www.wikidata.org/wiki/Property:P3761 | IPv4 routing prefix ]] or [[ https://www.wikidata.org/wiki/Property:P3793 | 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.
**Example**
Given the IP address `198.35.26.5` it is impossible to reason that the IP address belongs to [[ https://www.wikidata.org/wiki/Q180 | Wikimedia Foundation ]].
**Why Now?**
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. This would give stewards details about an IP address and help them make [[ https://www.wikidata.org/wiki/Q798599 | 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.
**Proposed Solution**
Based on the solution proposed in the [[ https://www.wikidata.org/wiki/Wikidata:Property_proposal/IP_range_start#Discussion | discussion ]], the best solution would be to fix the //storage// rather than duplicating the data.
Create a new [[ https://www.wikidata.org/wiki/Help:Data_type | data type ]] that extends from [[ https://www.wikidata.org/wiki/Help:Data_type#Quantity | 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.
**Work Arounds**
# 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`.