Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 1 | :mod:`ipaddress` --- IPv4/IPv6 manipulation library |
| 2 | =================================================== |
| 3 | |
| 4 | .. module:: ipaddress |
| 5 | :synopsis: IPv4/IPv6 manipulation library. |
| 6 | .. moduleauthor:: Peter Moody |
| 7 | |
| 8 | **Source code:** :source:`Lib/ipaddress.py` |
| 9 | |
| 10 | -------------- |
| 11 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 12 | .. note:: |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 13 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 14 | The ``ipaddress`` module has been included in the standard library on a |
| 15 | :term:`provisional basis <provisional package>`. Backwards incompatible |
| 16 | changes (up to and including removal of the package) may occur if deemed |
| 17 | necessary by the core developers. |
| 18 | |
| 19 | :mod:`ipaddress` provides the capabilities to create, manipulate and |
| 20 | operate on IPv4 and IPv6 addresses and networks. |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 21 | |
| 22 | The functions and classes in this module make it straightforward to handle |
| 23 | various tasks related to IP addresses, including checking whether or not two |
| 24 | hosts are on the same subnet, iterating over all hosts in a particular |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 25 | subnet, checking whether or not a string represents a valid IP address or |
| 26 | network definition, and so on. |
| 27 | |
| 28 | This is the full module API reference - for an overview and introduction, |
| 29 | see :ref:`ipaddress-howto`. |
| 30 | |
| 31 | .. versionadded:: 3.3 |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 32 | |
| 33 | |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 34 | Convenience factory functions |
| 35 | ----------------------------- |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 36 | |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 37 | The :mod:`ipaddress` module provides factory functions to conveniently create |
| 38 | IP addresses, networks and interfaces: |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 39 | |
| 40 | .. function:: ip_address(address) |
| 41 | |
| 42 | Return an :class:`IPv4Address` or :class:`IPv6Address` object depending on |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 43 | the IP address passed as argument. Either IPv4 or IPv6 addresses may be |
| 44 | supplied; integers less than 2**32 will be considered to be IPv4 by default. |
| 45 | A :exc:`ValueError` is raised if *address* does not represent a valid IPv4 or |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 46 | IPv6 address. |
| 47 | |
| 48 | >>> ipaddress.ip_address('192.168.0.1') |
| 49 | IPv4Address('192.168.0.1') |
| 50 | >>> ipaddress.ip_address('2001:db8::') |
| 51 | IPv6Address('2001:db8::') |
| 52 | |
| 53 | |
| 54 | .. function:: ip_network(address, strict=True) |
| 55 | |
| 56 | Return an :class:`IPv4Network` or :class:`IPv6Network` object depending on |
| 57 | the IP address passed as argument. *address* is a string or integer |
| 58 | representing the IP network. Either IPv4 or IPv6 networks may be supplied; |
| 59 | integers less than 2**32 will be considered to be IPv4 by default. *strict* |
| 60 | is passed to :class:`IPv4Network` or :class:`IPv6Network` constructor. A |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 61 | :exc:`ValueError` is raised if *address* does not represent a valid IPv4 or |
| 62 | IPv6 address, or if the network has host bits set. |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 63 | |
| 64 | >>> ipaddress.ip_network('192.168.0.0/28') |
| 65 | IPv4Network('192.168.0.0/28') |
| 66 | |
| 67 | |
| 68 | .. function:: ip_interface(address) |
| 69 | |
| 70 | Return an :class:`IPv4Interface` or :class:`IPv6Interface` object depending |
| 71 | on the IP address passed as argument. *address* is a string or integer |
| 72 | representing the IP address. Either IPv4 or IPv6 addresses may be supplied; |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 73 | integers less than 2**32 will be considered to be IPv4 by default. A |
| 74 | :exc:`ValueError` is raised if *address* does not represent a valid IPv4 or |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 75 | IPv6 address. |
| 76 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 77 | One downside of these convenience functions is that the need to handle both |
| 78 | IPv4 and IPv6 formats means that error messages provide minimal |
| 79 | information on the precise error, as the functions don't know whether the |
| 80 | IPv4 or IPv6 format was intended. More detailed error reporting can be |
| 81 | obtained by calling the appropriate version specific class constructors |
| 82 | directly. |
| 83 | |
| 84 | |
| 85 | IP Addresses |
| 86 | ------------ |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 87 | |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 88 | Address objects |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 89 | ^^^^^^^^^^^^^^^ |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 90 | |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 91 | The :class:`IPv4Address` and :class:`IPv6Address` objects share a lot of common |
| 92 | attributes. Some attributes that are only meaningful for IPv6 addresses are |
| 93 | also implemented by :class:`IPv4Address` objects, in order to make it easier to |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 94 | write code that handles both IP versions correctly. |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 95 | |
| 96 | .. class:: IPv4Address(address) |
| 97 | |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 98 | Construct an IPv4 address. An :exc:`AddressValueError` is raised if |
| 99 | *address* is not a valid IPv4 address. |
| 100 | |
| 101 | The following constitutes a valid IPv4 address: |
| 102 | |
| 103 | 1. A string in decimal-dot notation, consisting of four decimal integers in |
| 104 | the inclusive range 0-255, separated by dots (e.g. ``192.168.0.1``). Each |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 105 | integer represents an octet (byte) in the address. Leading zeroes are |
| 106 | tolerated only for values less then 8 (as there is no ambiguity |
| 107 | between the decimal and octal interpretations of such strings). |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 108 | 2. An integer that fits into 32 bits. |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 109 | 3. An integer packed into a :class:`bytes` object of length 4 (most |
| 110 | significant octet first). |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 111 | |
| 112 | >>> ipaddress.IPv4Address('192.168.0.1') |
| 113 | IPv4Address('192.168.0.1') |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 114 | >>> ipaddress.IPv4Address(3221225985) |
| 115 | IPv4Address('192.168.0.1') |
| 116 | >>> ipaddress.IPv4Address(b'\xC0\xA8\x00\x01') |
| 117 | IPv4Address('192.168.0.1') |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 118 | |
| 119 | .. attribute:: version |
| 120 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 121 | The appropriate version number: ``4`` for IPv4, ``6`` for IPv6. |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 122 | |
| 123 | .. attribute:: max_prefixlen |
| 124 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 125 | The total number of bits in the address representation for this |
| 126 | version: ``32`` for IPv4, ``128`` for IPv6. |
| 127 | |
| 128 | The prefix defines the number of leading bits in an address that |
| 129 | are compared to determine whether or not an address is part of a |
| 130 | network. |
| 131 | |
| 132 | .. attribute:: compressed |
| 133 | .. attribute:: exploded |
| 134 | |
| 135 | The string representation in dotted decimal notation. Leading zeroes |
| 136 | are never included in the representation. |
| 137 | |
| 138 | As IPv4 does not define a shorthand notation for addresses with octets |
| 139 | set to zero, these two attributes are always the same as ``str(addr)`` |
| 140 | for IPv4 addresses. Exposing these attributes makes it easier to |
| 141 | write display code that can handle both IPv4 and IPv6 addresses. |
| 142 | |
| 143 | .. attribute:: packed |
| 144 | |
| 145 | The binary representation of this address - a :class:`bytes` object of |
| 146 | the appropriate length (most significant octet first). This is 4 bytes |
| 147 | for IPv4 and 16 bytes for IPv6. |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 148 | |
| 149 | .. attribute:: is_multicast |
| 150 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 151 | ``True`` if the address is reserved for multicast use. See |
| 152 | :RFC:`3171` (for IPv4) or :RFC:`2373` (for IPv6). |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 153 | |
| 154 | .. attribute:: is_private |
| 155 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 156 | ``True`` if the address is allocated for private networks. See |
| 157 | :RFC:`1918` (for IPv4) or :RFC:`4193` (for IPv6). |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 158 | |
| 159 | .. attribute:: is_unspecified |
| 160 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 161 | ``True`` if the address is unspecified. See :RFC:`5375` (for IPv4) |
| 162 | or :RFC:`2373` (for IPv6). |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 163 | |
| 164 | .. attribute:: is_reserved |
| 165 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 166 | ``True`` if the address is otherwise IETF reserved. |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 167 | |
| 168 | .. attribute:: is_loopback |
| 169 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 170 | ``True`` if this is a loopback address. See :RFC:`3330` (for IPv4) |
| 171 | or :RFC:`2373` (for IPv6). |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 172 | |
| 173 | .. attribute:: is_link_local |
| 174 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 175 | ``True`` if the address is reserved for link-local usage. See |
| 176 | :RFC:`3927`. |
| 177 | |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 178 | |
| 179 | .. class:: IPv6Address(address) |
| 180 | |
| 181 | Construct an IPv6 address. An :exc:`AddressValueError` is raised if |
| 182 | *address* is not a valid IPv6 address. |
| 183 | |
| 184 | The following constitutes a valid IPv6 address: |
| 185 | |
| 186 | 1. A string consisting of eight groups of four hexadecimal digits, each |
| 187 | group representing 16 bits. The groups are separated by colons. |
| 188 | This describes an *exploded* (longhand) notation. The string can |
| 189 | also be *compressed* (shorthand notation) by various means. See |
| 190 | :RFC:`4291` for details. For example, |
| 191 | ``"0000:0000:0000:0000:0000:0abc:0007:0def"`` can be compressed to |
| 192 | ``"::abc:7:def"``. |
| 193 | 2. An integer that fits into 128 bits. |
| 194 | 3. An integer packed into a :class:`bytes` object of length 16, big-endian. |
| 195 | |
| 196 | >>> ipaddress.IPv6Address('2001:db8::1000') |
| 197 | IPv6Address('2001:db8::1000') |
| 198 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 199 | .. attribute:: compressed |
| 200 | |
| 201 | The short form of the address representation, with leading zeroes in |
| 202 | groups omitted and the longest sequence of groups consisting entirely of |
| 203 | zeroes collapsed to a single empty group. |
| 204 | |
| 205 | This is also the value returned by ``str(addr)`` for IPv6 addresses. |
| 206 | |
| 207 | .. attribute:: exploded |
| 208 | |
| 209 | The long form of the address representation, with all leading zeroes and |
| 210 | groups consisting entirely of zeroes included. |
| 211 | |
| 212 | .. attribute:: packed |
| 213 | .. attribute:: version |
| 214 | .. attribute:: max_prefixlen |
| 215 | .. attribute:: is_multicast |
| 216 | .. attribute:: is_private |
| 217 | .. attribute:: is_unspecified |
| 218 | .. attribute:: is_reserved |
| 219 | .. attribute:: is_loopback |
| 220 | .. attribute:: is_link_local |
| 221 | |
| 222 | Refer to the corresponding attribute documentation in |
| 223 | :class:`IPv4Address` |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 224 | |
| 225 | .. attribute:: is_site_local |
| 226 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 227 | ``True`` if the address is reserved for site-local usage. Note that |
| 228 | the site-local address space has been deprecated by :RFC:`3879`. Use |
| 229 | :attr:`~IPv4Address.is_private` to test if this address is in the |
| 230 | space of unique local addresses as defined by :RFC:`4193`. |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 231 | |
| 232 | .. attribute:: ipv4_mapped |
| 233 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 234 | For addresses that appear to be IPv4 mapped addresses (starting with |
| 235 | ``::FFFF/96``), this property will report the embedded IPv4 address. |
| 236 | For any other address, this property will be ``None``. |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 237 | |
| 238 | .. attribute:: sixtofour |
| 239 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 240 | For addresses that appear to be 6to4 addresses (starting with |
| 241 | ``2002::/16``) as defined by :RFC:`3056`, this property will report |
| 242 | the embedded IPv4 address. For any other address, this property will |
| 243 | be ``None``. |
| 244 | |
| 245 | .. attribute:: teredo |
| 246 | |
| 247 | For addresses that appear to be Teredo addresses (starting with |
| 248 | ``2001::/32``) as defined by :RFC:`4380`, this property will report |
| 249 | the embedded ``(server, client)`` IP address pair. For any other |
| 250 | address, this property will be ``None``. |
| 251 | |
| 252 | |
| 253 | Conversion to Strings and Integers |
| 254 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 255 | |
| 256 | To interoperate with networking interfaces such as the socket module, |
| 257 | addresses must be converted to strings or integers. This is handled using |
| 258 | the :func:`str` and :func:`int` builtin functions:: |
| 259 | |
| 260 | >>> str(ipaddress.IPv4Address('192.168.0.1')) |
| 261 | '192.168.0.1' |
| 262 | >>> int(ipaddress.IPv4Address('192.168.0.1')) |
| 263 | 3232235521 |
| 264 | >>> str(ipaddress.IPv6Address('::1')) |
| 265 | '::1' |
| 266 | >>> int(ipaddress.IPv6Address('::1')) |
| 267 | 1 |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 268 | |
| 269 | |
| 270 | Operators |
| 271 | ^^^^^^^^^ |
| 272 | |
| 273 | Address objects support some operators. Unless stated otherwise, operators can |
| 274 | only be applied between compatible objects (i.e. IPv4 with IPv4, IPv6 with |
| 275 | IPv6). |
| 276 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 277 | |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 278 | Logical operators |
| 279 | """"""""""""""""" |
| 280 | |
| 281 | Address objects can be compared with the usual set of logical operators. Some |
| 282 | examples:: |
| 283 | |
| 284 | >>> IPv4Address('127.0.0.2') > IPv4Address('127.0.0.1') |
| 285 | True |
| 286 | >>> IPv4Address('127.0.0.2') == IPv4Address('127.0.0.1') |
| 287 | False |
| 288 | >>> IPv4Address('127.0.0.2') != IPv4Address('127.0.0.1') |
| 289 | True |
| 290 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 291 | |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 292 | Arithmetic operators |
| 293 | """""""""""""""""""" |
| 294 | |
| 295 | Integers can be added to or subtracted from address objects. Some examples:: |
| 296 | |
| 297 | >>> IPv4Address('127.0.0.2') + 3 |
| 298 | IPv4Address('127.0.0.5') |
| 299 | >>> IPv4Address('127.0.0.2') - 3 |
| 300 | IPv4Address('126.255.255.255') |
| 301 | >>> IPv4Address('255.255.255.255') + 1 |
| 302 | Traceback (most recent call last): |
| 303 | File "<stdin>", line 1, in <module> |
| 304 | ipaddress.AddressValueError: 4294967296 (>= 2**32) is not permitted as an IPv4 address |
| 305 | |
| 306 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 307 | IP Network definitions |
| 308 | ---------------------- |
| 309 | |
| 310 | The :class:`IPv4Network` and :class:`IPv6Network` objects provide a mechanism |
| 311 | for defining and inspecting IP network definitions. A network definition |
| 312 | consists of a *mask* and a *network address*, and as such defines a range of |
| 313 | IP addresses that equal the network address when masked (binary AND) with the |
| 314 | mask. For example, a network definition with the mask ``255.255.255.0`` and |
| 315 | the network address ``192.168.1.0`` consists of IP addresses in the inclusive |
| 316 | range ``192.168.1.0`` to ``192.168.1.255``. |
| 317 | |
| 318 | |
| 319 | Prefix, net mask and host mask |
| 320 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 321 | |
| 322 | There are several equivalent ways to specify IP network masks. A *prefix* |
| 323 | ``/<nbits>`` is a notation that denotes how many high-order bits are set in |
| 324 | the network mask. A *net mask* is an IP address with some number of |
| 325 | high-order bits set. Thus the prefix ``/24`` is equivalent to the net mask |
| 326 | ``255.255.255.0`` in IPv4, or ``ffff:ff00::`` in IPv6. In addition, a |
| 327 | *host mask* is the logical inverse of a *net mask*, and is sometimes used |
| 328 | (for example in Cisco access control lists) to denote a network mask. The |
| 329 | host mask equivalent to ``/24`` in IPv4 is ``0.0.0.255``. |
| 330 | |
| 331 | |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 332 | Network objects |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 333 | ^^^^^^^^^^^^^^^ |
| 334 | |
| 335 | All attributes implemented by address objects are implemented by network |
| 336 | objects as well. In addition, network objects implement additional attributes. |
| 337 | All of these are common between :class:`IPv4Network` and :class:`IPv6Network`, |
| 338 | so to avoid duplication they are only documented for :class:`IPv4Network`. |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 339 | |
| 340 | .. class:: IPv4Network(address, strict=True) |
| 341 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 342 | Construct an IPv4 network definition. *address* can be one of the following: |
| 343 | |
| 344 | 1. A string consisting of an IP address and an optional mask, separated by |
| 345 | a slash (``/``). The IP address is the network address, and the mask |
| 346 | can be either a single number, which means it's a *prefix*, or a string |
| 347 | representation of an IPv4 address. If it's the latter, the mask is |
| 348 | interpreted as a *net mask* if it starts with a non-zero field, or as |
| 349 | a *host mask* if it starts with a zero field. If no mask is provided, |
| 350 | it's considered to be ``/32``. |
| 351 | |
| 352 | For example, the following *address* specifications are equivalent: |
| 353 | ``192.168.1.0/24``, ``192.168.1.0/255.255.255.0`` and |
| 354 | ``192.168.1.0/0.0.0.255``. |
| 355 | |
| 356 | 2. An integer that fits into 32 bits. This is equivalent to a |
| 357 | single-address network, with the network address being *address* and |
| 358 | the mask being ``/32``. |
| 359 | |
| 360 | 3. An integer packed into a :class:`bytes` object of length 4, big-endian. |
| 361 | The interpretation is similar to an integer *address*. |
| 362 | |
| 363 | An :exc:`AddressValueError` is raised if *address* is not a valid IPv4 |
| 364 | address. A :exc:`NetmaskValueError` is raised if the mask is not valid for |
| 365 | an IPv4 address. |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 366 | |
| 367 | If *strict* is ``True`` and host bits are set in the supplied address, |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 368 | then :exc:`ValueError` is raised. Otherwise, the host bits are masked out |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 369 | to determine the appropriate network address. |
| 370 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 371 | Unless stated otherwise, all network methods accepting other network/address |
| 372 | objects will raise :exc:`TypeError` if the argument's IP version is |
| 373 | incompatible to ``self`` |
| 374 | |
| 375 | .. attribute:: version |
| 376 | .. attribute:: max_prefixlen |
| 377 | |
| 378 | Refer to the corresponding attribute documentation in |
| 379 | :class:`IPv4Address` |
| 380 | |
| 381 | .. attribute:: is_multicast |
| 382 | .. attribute:: is_private |
| 383 | .. attribute:: is_unspecified |
| 384 | .. attribute:: is_reserved |
| 385 | .. attribute:: is_loopback |
| 386 | .. attribute:: is_link_local |
| 387 | |
| 388 | These attributes are true for the network as a whole if they are true |
| 389 | true for both the network address and the broadcast address |
| 390 | |
| 391 | .. attribute:: network_address |
| 392 | |
| 393 | The broadcast address for the network. |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 394 | |
| 395 | .. attribute:: broadcast_address |
| 396 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 397 | The broadcast address for the network. |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 398 | |
| 399 | .. attribute:: host mask |
| 400 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 401 | The host mask, as a string. |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 402 | |
| 403 | .. attribute:: with_prefixlen |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 404 | .. attribute:: compressed |
| 405 | .. attribute:: exploded |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 406 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 407 | A string representation of the network, with the mask in prefix |
| 408 | notation. |
| 409 | |
| 410 | ``with_prefixlen`` and ``compressed`` are always the same as |
| 411 | ``str(network)``. |
| 412 | ``exploded`` uses the exploded form the network address. |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 413 | |
| 414 | .. attribute:: with_netmask |
| 415 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 416 | A string representation of the network, with the mask in net mask |
| 417 | notation. |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 418 | |
| 419 | .. attribute:: with_hostmask |
| 420 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 421 | A string representation of the network, with the mask in host mask |
| 422 | notation. |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 423 | |
| 424 | .. attribute:: num_addresses |
| 425 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 426 | The total number of addresses in the network. |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 427 | |
| 428 | .. attribute:: prefixlen |
| 429 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 430 | Length of the network prefix, in bits. |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 431 | |
| 432 | .. method:: hosts() |
| 433 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 434 | Returns an iterator over the usable hosts in the network. The usable |
| 435 | hosts are all the IP addresses that belong to the network, except the |
| 436 | network address itself and the network broadcast address. |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 437 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 438 | >>> list(ip_network('192.0.2.0/29').hosts()) |
| 439 | [IPv4Address('192.0.2.1'), IPv4Address('192.0.2.2'), |
| 440 | IPv4Address('192.0.2.3'), IPv4Address('192.0.2.4'), |
| 441 | IPv4Address('192.0.2.5'), IPv4Address('192.0.2.6')] |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 442 | |
| 443 | .. method:: overlaps(other) |
| 444 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 445 | ``True`` if this network is partly or wholly contained in *other* or |
| 446 | or *other* is wholly contained in this network. |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 447 | |
| 448 | .. method:: address_exclude(network) |
| 449 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 450 | Computes the network definitions resulting from removing the given |
| 451 | *network* from this one. Returns an iterator of network objects. |
| 452 | Raises :exc:`ValueError` if *network* is not completely contained in |
| 453 | this network. |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 454 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 455 | >>> n1 = ip_network('192.0.2.0/28') |
| 456 | >>> n2 = ip_network('192.0.2.1/32') |
| 457 | >>> list(n1.address_exclude(n2)) |
| 458 | [IPv4Network('192.0.2.8/29'), IPv4Network('192.0.2.4/30'), |
| 459 | IPv4Network('192.0.2.2/31'), IPv4Network('192.0.2.0/32')] |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 460 | |
| 461 | .. method:: subnets(prefixlen_diff=1, new_prefix=None) |
| 462 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 463 | The subnets that join to make the current network definition, depending |
| 464 | on the argument values. *prefixlen_diff* is the amount our prefix |
| 465 | length should be increased by. *new_prefix* is the desired new |
| 466 | prefix of the subnets; it must be larger than our prefix. One and |
| 467 | only one of *prefixlen_diff* and *new_prefix* must be set. Returns an |
| 468 | iterator of network objects. |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 469 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 470 | >>> list(ip_network('192.0.2.0/24').subnets()) |
| 471 | [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/25')] |
| 472 | >>> list(ip_network('192.0.2.0/24').subnets(prefixlen_diff=2)) |
| 473 | [IPv4Network('192.0.2.0/26'), IPv4Network('192.0.2.64/26'), |
| 474 | IPv4Network('192.0.2.128/26'), IPv4Network('192.0.2.192/26')] |
| 475 | >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=26)) |
| 476 | [IPv4Network('192.0.2.0/26'), IPv4Network('192.0.2.64/26'), |
| 477 | IPv4Network('192.0.2.128/26'), IPv4Network('192.0.2.192/26')] |
| 478 | >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=23)) |
| 479 | Traceback (most recent call last): |
| 480 | File "<stdin>", line 1, in <module> |
| 481 | raise ValueError('new prefix must be longer') |
| 482 | ValueError: new prefix must be longer |
| 483 | >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=25)) |
| 484 | [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/25')] |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 485 | |
| 486 | .. method:: supernet(prefixlen_diff=1, new_prefix=None) |
| 487 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 488 | The supernet containing this network definition, depending on the |
| 489 | argument values. *prefixlen_diff* is the amount our prefix length |
| 490 | should be decreased by. *new_prefix* is the desired new prefix of |
| 491 | the supernet; it must be smaller than our prefix. One and only one |
| 492 | of *prefixlen_diff* and *new_prefix* must be set. Returns a single |
| 493 | network object. |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 494 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 495 | >>> ip_network('192.0.2.0/24').supernet() |
| 496 | IPv4Network('192.0.2.0/23') |
| 497 | >>> ip_network('192.0.2.0/24').supernet(prefixlen_diff=2) |
| 498 | IPv4Network('192.0.0.0/22') |
| 499 | >>> ip_network('192.0.2.0/24').supernet(new_prefix=20) |
| 500 | IPv4Network('192.0.0.0/20') |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 501 | |
| 502 | .. method:: compare_networks(other) |
| 503 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 504 | Compare this network to *other*. In this comparison only the network |
| 505 | addresses are considered; host bits aren't. Returns either ``-1``, |
| 506 | ``0`` or ``1``. |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 507 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 508 | >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.2/32')) |
| 509 | -1 |
| 510 | >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.0/32')) |
| 511 | 1 |
| 512 | >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.1/32')) |
| 513 | 0 |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 514 | |
| 515 | |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 516 | .. class:: IPv6Network(address, strict=True) |
| 517 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 518 | Construct an IPv6 network definition. *address* can be one of the following: |
| 519 | |
| 520 | 1. A string consisting of an IP address and an optional mask, separated by |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 521 | a slash (``/``). The IP address is the network address, and the mask |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 522 | can be either a single number, which means it's a *prefix*, or a string |
| 523 | representation of an IPv6 address. If it's the latter, the mask is |
| 524 | interpreted as a *net mask*. If no mask is provided, it's considered to |
| 525 | be ``/128``. |
| 526 | |
| 527 | For example, the following *address* specifications are equivalent: |
| 528 | ``2001:db00::0/24`` and ``2001:db00::0/ffff:ff00::``. |
| 529 | |
| 530 | 2. An integer that fits into 128 bits. This is equivalent to a |
| 531 | single-address network, with the network address being *address* and |
| 532 | the mask being ``/128``. |
| 533 | |
| 534 | 3. An integer packed into a :class:`bytes` object of length 16, bit-endian. |
| 535 | The interpretation is similar to an integer *address*. |
| 536 | |
| 537 | An :exc:`AddressValueError` is raised if *address* is not a valid IPv6 |
| 538 | address. A :exc:`NetmaskValueError` is raised if the mask is not valid for |
| 539 | an IPv6 address. |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 540 | |
| 541 | If *strict* is ``True`` and host bits are set in the supplied address, |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 542 | then :exc:`ValueError` is raised. Otherwise, the host bits are masked out |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 543 | to determine the appropriate network address. |
| 544 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 545 | .. attribute:: version |
| 546 | .. attribute:: max_prefixlen |
| 547 | .. attribute:: is_multicast |
| 548 | .. attribute:: is_private |
| 549 | .. attribute:: is_unspecified |
| 550 | .. attribute:: is_reserved |
| 551 | .. attribute:: is_loopback |
| 552 | .. attribute:: is_link_local |
| 553 | .. attribute:: network_address |
| 554 | .. attribute:: broadcast_address |
| 555 | .. attribute:: host mask |
| 556 | .. attribute:: with_prefixlen |
| 557 | .. attribute:: compressed |
| 558 | .. attribute:: exploded |
| 559 | .. attribute:: with_netmask |
| 560 | .. attribute:: with_hostmask |
| 561 | .. attribute:: num_addresses |
| 562 | .. attribute:: prefixlen |
| 563 | .. method:: hosts() |
| 564 | .. method:: overlaps(other) |
| 565 | .. method:: address_exclude(network) |
| 566 | .. method:: subnets(prefixlen_diff=1, new_prefix=None) |
| 567 | .. method:: supernet(prefixlen_diff=1, new_prefix=None) |
| 568 | .. method:: compare_networks(other) |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 569 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 570 | Refer to the corresponding attribute documentation in |
| 571 | :class:`IPv4Network` |
| 572 | |
| 573 | .. attribute:: is_site_local |
| 574 | |
| 575 | These attribute is true for the network as a whole if it is true |
| 576 | true for both the network address and the broadcast address |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 577 | |
| 578 | |
| 579 | Operators |
| 580 | ^^^^^^^^^ |
| 581 | |
| 582 | Network objects support some operators. Unless stated otherwise, operators can |
| 583 | only be applied between compatible objects (i.e. IPv4 with IPv4, IPv6 with |
| 584 | IPv6). |
| 585 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 586 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 587 | Logical operators |
| 588 | """"""""""""""""" |
| 589 | |
| 590 | Network objects can be compared with the usual set of logical operators, |
| 591 | similarly to address objects. |
| 592 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 593 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 594 | Iteration |
| 595 | """"""""" |
| 596 | |
| 597 | Network objects can be iterated to list all the addresses belonging to the |
| 598 | network. For iteration, *all* hosts are returned, including unusable hosts |
| 599 | (for usable hosts, use the :meth:`~IPv4Network.hosts` method). An |
| 600 | example:: |
| 601 | |
| 602 | >>> for addr in IPv4Network('192.0.2.0/28'): |
| 603 | ... addr |
| 604 | ... |
| 605 | IPv4Address('192.0.2.0') |
| 606 | IPv4Address('192.0.2.1') |
| 607 | IPv4Address('192.0.2.2') |
| 608 | IPv4Address('192.0.2.3') |
| 609 | IPv4Address('192.0.2.4') |
| 610 | IPv4Address('192.0.2.5') |
| 611 | IPv4Address('192.0.2.6') |
| 612 | IPv4Address('192.0.2.7') |
| 613 | IPv4Address('192.0.2.8') |
| 614 | IPv4Address('192.0.2.9') |
| 615 | IPv4Address('192.0.2.10') |
| 616 | IPv4Address('192.0.2.11') |
| 617 | IPv4Address('192.0.2.12') |
| 618 | IPv4Address('192.0.2.13') |
| 619 | IPv4Address('192.0.2.14') |
| 620 | IPv4Address('192.0.2.15') |
| 621 | |
Nick Coghlan | 7362c3e | 2012-08-05 22:32:37 +1000 | [diff] [blame^] | 622 | |
Nick Coghlan | 730f67f | 2012-08-05 22:02:18 +1000 | [diff] [blame] | 623 | Networks as containers of addresses |
| 624 | """"""""""""""""""""""""""""""""""" |
| 625 | |
| 626 | Network objects can act as containers of addresses. Some examples:: |
| 627 | |
| 628 | >>> IPv4Network('192.0.2.0/28')[0] |
| 629 | IPv4Address('192.0.2.0') |
| 630 | >>> IPv4Network('192.0.2.0/28')[15] |
| 631 | IPv4Address('192.0.2.15') |
| 632 | >>> IPv4Address('192.0.2.6') in IPv4Network('192.0.2.0/28') |
| 633 | True |
| 634 | >>> IPv4Address('192.0.3.6') in IPv4Network('192.0.2.0/28') |
| 635 | False |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 636 | |
| 637 | |
Eli Bendersky | 0e49749 | 2012-07-31 17:23:11 +0300 | [diff] [blame] | 638 | Interface objects |
| 639 | ----------------- |
| 640 | |
| 641 | .. class:: IPv4Interface(address) |
| 642 | |
| 643 | Construct an IPv4 interface. *address* is a string or integer representing |
| 644 | the IP interface. An :exc:`AddressValueError` is raised if *address* is not |
| 645 | a valid IPv4 address. |
| 646 | |
| 647 | The network address for the interface is determined by calling |
| 648 | ``IPv4Network(address, strict=False)``. |
| 649 | |
| 650 | >>> ipaddress.IPv4Interface('192.168.0.0/24') |
| 651 | IPv4Interface('192.168.0.0/24') |
| 652 | >>> ipaddress.IPv4Interface('192.168.0.0/24').network |
| 653 | IPv4Network('192.168.0.0/24') |
| 654 | |
| 655 | |
| 656 | .. class:: IPv6Interface(address) |
| 657 | |
| 658 | Construct an IPv6 interface. *address* is a string or integer representing |
| 659 | the IP interface. An :exc:`AddressValueError` is raised if *address* is not |
| 660 | a valid IPv6 address. |
| 661 | |
| 662 | The network address for the interface is determined by calling |
| 663 | ``IPv6Network(address, strict=False)``. |
| 664 | |
| 665 | >>> ipaddress.IPv6Interface('2001:db8::1000/96') |
| 666 | IPv6Interface('2001:db8::1000/96') |
| 667 | >>> ipaddress.IPv6Interface('2001:db8::1000/96').network |
| 668 | IPv6Network('2001:db8::/96') |
| 669 | |
| 670 | |
Nick Coghlan | 9680bdb | 2012-06-17 17:24:10 +1000 | [diff] [blame] | 671 | Other Module Level Functions |
| 672 | ---------------------------- |
| 673 | |
| 674 | The module also provides the following module level functions: |
| 675 | |
| 676 | .. function:: v4_int_to_packed(address) |
| 677 | |
| 678 | Represent an address as 4 packed bytes in network (big-endian) order. |
| 679 | *address* is an integer representation of an IPv4 IP address. A |
| 680 | :exc:`ValueError` is raised if the integer is negative or too large to be an |
| 681 | IPv4 IP address. |
| 682 | |
| 683 | >>> ipaddress.ip_address(3221225985) |
| 684 | IPv4Address('192.0.2.1') |
| 685 | >>> ipaddress.v4_int_to_packed(3221225985) |
| 686 | b'\xc0\x00\x02\x01' |
| 687 | |
| 688 | |
| 689 | .. function:: v6_int_to_packed(address) |
| 690 | |
| 691 | Represent an address as 16 packed bytes in network (big-endian) order. |
| 692 | *address* is an integer representation of an IPv6 IP address. A |
| 693 | :exc:`ValueError` is raised if the integer is negative or too large to be an |
| 694 | IPv6 IP address. |
| 695 | |
| 696 | |
| 697 | .. function:: summarize_address_range(first, last) |
| 698 | |
| 699 | Return an iterator of the summarized network range given the first and last |
| 700 | IP addresses. *first* is the first :class:`IPv4Address` or |
| 701 | :class:`IPv6Address` in the range and *last* is the last :class:`IPv4Address` |
| 702 | or :class:`IPv6Address` in the range. A :exc:`TypeError` is raised if |
| 703 | *first* or *last* are not IP addresses or are not of the same version. A |
| 704 | :exc:`ValueError` is raised if *last* is not greater than *first* or if |
| 705 | *first* address version is not 4 or 6. |
| 706 | |
| 707 | >>> [ipaddr for ipaddr in ipaddress.summarize_address_range( |
| 708 | ... ipaddress.IPv4Address('192.0.2.0'), |
| 709 | ... ipaddress.IPv4Address('192.0.2.130'))] |
| 710 | [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/31'), IPv4Network('192.0.2.130/32')] |
| 711 | |
| 712 | |
| 713 | .. function:: collapse_addresses(addresses) |
| 714 | |
| 715 | Return an iterator of the collapsed :class:`IPv4Network` or |
| 716 | :class:`IPv6Network` objects. *addresses* is an iterator of |
| 717 | :class:`IPv4Network` or :class:`IPv6Network` objects. A :exc:`TypeError` is |
| 718 | raised if *addresses* contains mixed version objects. |
| 719 | |
| 720 | >>> [ipaddr for ipaddr in |
| 721 | ... ipaddress.collapse_addresses([ipaddress.IPv4Network('192.0.2.0/25'), |
| 722 | ... ipaddress.IPv4Network('192.0.2.128/25')])] |
| 723 | [IPv4Network('192.0.2.0/24')] |
| 724 | |
| 725 | |
| 726 | .. function:: get_mixed_type_key(obj) |
| 727 | |
| 728 | Return a key suitable for sorting between networks and addresses. Address |
| 729 | and Network objects are not sortable by default; they're fundamentally |
| 730 | different, so the expression:: |
| 731 | |
| 732 | IPv4Address('192.0.2.0') <= IPv4Network('192.0.2.0/24') |
| 733 | |
| 734 | doesn't make sense. There are some times however, where you may wish to |
| 735 | have :mod:`ipaddress` sort these anyway. If you need to do this, you can use |
| 736 | this function as the ``key`` argument to :func:`sorted()`. |
| 737 | |
| 738 | *obj* is either a network or address object. |
| 739 | |
| 740 | |
| 741 | Custom Exceptions |
| 742 | ----------------- |
| 743 | |
| 744 | To support more specific error reporting from class constructors, the |
| 745 | module defines the following exceptions: |
| 746 | |
| 747 | .. exception:: AddressValueError(ValueError) |
| 748 | |
| 749 | Any value error related to the address. |
| 750 | |
| 751 | |
| 752 | .. exception:: NetmaskValueError(ValueError) |
| 753 | |
| 754 | Any value error related to the netmask. |