iptools

raw JSON →
0.7.0 verified Mon Apr 27 auth: no python maintenance

Python utilities for manipulating IPv4 and IPv6 addresses, including validation, subnetting, range operations, and RFC 1924 encoding/decoding. Current version 0.7.0, last updated 2016; in maintenance mode with low release cadence.

pip install iptools
error AttributeError: module 'iptools' has no attribute 'IpRange'
cause Incorrect import path or namespace issue.
fix
Use 'from iptools import IpRange' instead of 'import iptools; iptools.IpRange'.
error OverflowError: Python int too large to convert to C long
cause Very large IP ranges (e.g., IPv6) cause overflow in range calculation.
fix
Use smaller range chunks or upgrade to iptools >= 0.7.0 which includes a fix for large ranges but may still have limits.
error ValueError: invalid literal for int() with base 10: ...
cause Passing a CIDR string to IpRange where start and end addresses are expected.
fix
Use IpRange with two IP addresses, not a CIDR. For CIDR, use IpRangeList(['192.168.1.0/24']) or parse manually.
breaking IpRange and IpRangeList do not support IPv6 CIDR notation directly; use IpRange with start/end addresses.
fix For IPv6 ranges, create IpRange with two IPv6 addresses: IpRange('::1', '::ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff').
deprecated The library is in maintenance mode; no new features are planned. Consider alternatives like ipaddress (stdlib) for IPv4/IPv6 manipulation.
fix Use ipaddress from Python standard library.
gotcha validate_netmask may raise OverflowError for certain netmask values; fixed in 0.7.0 but still a potential issue if using older versions.
fix Upgrade to iptools >= 0.7.0.

Simple validation, IP range creation, and list operations.

from iptools import IpRange, IpRangeList, validate_cidr

# Validate a CIDR range
if validate_cidr('192.168.1.0/24'):
    print('Valid CIDR')

# Create an IP range and iterate
r = IpRange('192.168.1.0', '192.168.1.255')
for ip in r:
    print(ip)

# Combine ranges
rl = IpRangeList(['192.168.1.0/24', '10.0.0.0/8'])
print(rl)