ipaddr: IP address manipulation in SQLite

The sqlean-ipaddr extension provides functions to manipulate IPs and subnets.

⚠️ This extension is not available on Windows.

ReferenceAcknowledgementsInstallation and usage

Reference

containsfamilyhostmasklennetwork

ipcontains

ipcontains(subnet, ip)

Reports whether subnet contains ip (which may be another subnet).

select ipcontains('192.168.16.0/24', '192.168.16.3');
-- 1

ipfamily

ipfamily(ip)

Returns the family of a specified IP address.

select ipfamily('192.168.1.1');
-- 4

iphost

iphost(ip)

Returns the host part of an IP address.

select iphost('2001:db8::123/64');
-- 2001:db8::123

ipmasklen

ipmasklen(ip)

Returns the prefix length of an IP address.

select ipmasklen('192.168.16.12/24');
-- 24

ipnetwork

ipnetwork(ip)

Returns the network part of an IP address.

select ipnetwork('192.168.16.12/24');
-- 192.168.16.0/24

Acknowledgements

Contributed by Vincent Bernat.

Installation and usage

SQLite command-line interface:

sqlite> .load ./ipaddr
sqlite> select ipfamily('2001:db8::1');

See How to install an extension for usage with IDE, Python, etc.

Download the extension.

Explore other extensions.

Subscribe to stay on top of new features.