@@ -9,11 +9,11 @@ An Introduction to the ipaddress module
99
1010.. topic :: Overview
1111
12- This document aims to provide a gentle introduction to :mod: ` ipaddress `
13- module. It is aimed primarily at users that aren't already familiar with
14- IP networking terminology, but may also be useful to network engineers
15- wanting an overview of how the ipaddress module represents IP network
16- addressing concepts.
12+ This document aims to provide a gentle introduction to the
13+ :mod: ` ipaddress ` module. It is aimed primarily at users that aren't
14+ already familiar with IP networking terminology, but may also be useful
15+ to network engineers wanting an overview of how :mod: ` ipaddress `
16+ represents IP network addressing concepts.
1717
1818
1919Creating Address/Network/Interface objects
@@ -45,8 +45,9 @@ IP Host Addresses
4545
4646Addresses, often referred to as "host addresses" are the most basic unit
4747when working with IP addressing. The simplest way to create addresses is
48- to use the :func: `ipaddress.ip_address ` factory function, which automatically determines
49- whether to create an IPv4 or IPv6 address based on the passed in value::
48+ to use the :func: `ipaddress.ip_address ` factory function, which automatically
49+ determines whether to create an IPv4 or IPv6 address based on the passed in
50+ value::
5051
5152 >>> ipaddress.ip_address('192.0.2.1')
5253 IPv4Address('192.0.2.1')
@@ -121,16 +122,17 @@ integer, so the network prefix includes the entire network address::
121122 >>> ipaddress.ip_network(42540766411282592856903984951653826560)
122123 IPv6Network('2001:db8::/128')
123124
124- Creation of a particular kind of network can be forced by calling the
125- class constructor directly instead of using the factory function.
125+ As with addresses, creation of a particular kind of network can be forced
126+ by calling the class constructor directly instead of using the factory
127+ function.
126128
127129
128130Host Interfaces
129131---------------
130132
131133As mentioned just above, if you need to describe an address on a particular
132134network, neither the address nor the network classes are sufficient.
133- Notation like ``192.0.2.1/24 `` is commonly used network engineers and the
135+ Notation like ``192.0.2.1/24 `` is commonly used by network engineers and the
134136people who write tools for firewalls and routers as shorthand for "the host
135137``192.0.2.1 `` on the network ``192.0.2.0/24 ``", Accordingly, :mod: `ipaddress `
136138provides a set of hybrid classes that associate an address with a particular
@@ -213,10 +215,19 @@ the hostmask (any bits that are not part of the netmask):
213215
214216Exploding or compressing the address::
215217
216- >>> net6.exploded
217- '2001:0000:0000:0000:0000:0000:0000:0000/96'
218218 >>> addr6.exploded
219- '2001:0000:0000:0000:0000:0000:0000:0001'
219+ '2001:0db8:0000:0000:0000:0000:0000:0000'
220+ >>> addr6.compressed
221+ '2001:db8::'
222+ >>> net6.exploded
223+ '2001:0db8:0000:0000:0000:0000:0000:0000/96'
224+ >>> net6.compressed
225+ '2001:db8::/96'
226+
227+ While IPv4 doesn't support explosion or compression, the associated objects
228+ still provide the relevant properties so that version neutral code can
229+ easily ensure the most concise or most verbose form is used for IPv6
230+ addresses while still correctly handling IPv4 addresses.
220231
221232
222233Networks as lists of Addresses
0 commit comments