Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,49 @@
About
=====

This module allows you to perform IP subnet calculations, there is support for
both IPv4 and IPv6 CIDR notation.

Example Usage
=============
The ipcalc module provides tools for IP address manipulation and calculation,
allowing operations such as iterating over hosts, checking network membership,
calculating netmasks, and converting addresses to integers.

```python
Classes:
IP: Represents an IP address (IPv4 or IPv6).
Network: Represents an IP network, supporting iteration and membership tests.

Example:

>>> import ipcalc
>>> for x in ipcalc.Network('172.16.42.0/30'):
... print str(x)
... print(str(x))
...
172.16.42.1
172.16.42.2

>>> subnet = ipcalc.Network('2001:beef:babe::/48')
>>> print(str(subnet.network()))
2001:beef:babe:0000:0000:0000:0000:0000
>>> print(str(subnet.netmask()))
ffff:ffff:ffff:0000:0000:0000:0000:0000
>>> '192.168.42.23' in Network('192.168.42.0/24')

>>> '192.168.42.23' in ipcalc.Network('192.168.42.0/24')
True
>>> int(IP('fe80::213:ceff:fee8:c937'))

>>> int(ipcalc.IP('fe80::213:ceff:fee8:c937'))
338288524927261089654168587652869703991
```

Args:
address (str): The IP address or network in CIDR notation.
version (int, optional): The IP version (4 or 6). Defaults to auto-detection.

Returns:
Network or IP object depending on the class initialized.

Raises:
ValueError: If the provided address is invalid.
TypeError: If an unsupported argument type is passed.




Bugs/Features
=============
Expand Down