Google's IP Address Manipulation Library

2.2.0 · deprecated · verified Tue Apr 14

ipaddr (pypi-slug: ipaddr) is a Python library developed by Google for manipulating IPv4 and IPv6 addresses and networks. It provides functionalities for validation, subnet operations, and summarization. The last release was version 2.2.0 in 2017. This library has been superseded by the `ipaddress` module, which is part of the Python 3 standard library.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create IP address and network objects using the `ipaddr` library, check their properties, and perform basic network membership tests.

import ipaddr

# Create an IPv4 address object
ip_v4 = ipaddr.IPAddress('192.168.1.1')
print(f"IPv4 Address: {ip_v4}")
print(f"Is private: {ip_v4.is_private}")

# Create an IPv6 address object
ip_v6 = ipaddr.IPAddress('2001:db8::1')
print(f"IPv6 Address: {ip_v6}")

# Create a network object
network = ipaddr.IPNetwork('192.168.1.0/24')
print(f"Network: {network}")
print(f"Network address: {network.network}")
print(f"Broadcast address: {network.broadcast}")
print(f"Number of hosts: {network.numhosts}")

# Check if an address is in a network
print(f"192.168.1.5 in network: {ipaddr.IPAddress('192.168.1.5') in network}")

view raw JSON →