"ipaddress" --- IPv4/IPv6 操作ライブラリ
****************************************

**ソースコード:** Lib/ipaddress.py

======================================================================

"ipaddress" は IPv4 と IPv6 アドレスとネットワークの生成・変更・操作を
提供しています。

このモジュールの関数やクラスを使うと、IPアドレスに関する様々なタスク、
例えば2つのホストが同じサブネットに属しているかどうかをチェックしたり
、特定のサブネット内の全てのホストをイテレートしたり、文字列が正しい
IP アドレスかネットワークを定義しているかどうかをチェックするなどを簡
単に実現することができます。

これはモジュールの完全な API リファレンスです。概要や紹介は ipaddress
モジュールの紹介 を参照してください。

バージョン 3.3 で追加.


便利なファクトリ関数
====================

"ipaddress" モジュールは簡単に IP アドレス、ネットワーク、インターフェ
ースを生成するためのファクトリ関数を提供しています:

ipaddress.ip_address(address)

   Return an "IPv4Address" or "IPv6Address" object depending on the IP
   address passed as argument.  Either IPv4 or IPv6 addresses may be
   supplied; integers less than "2**32" will be considered to be IPv4
   by default. A "ValueError" is raised if *address* does not
   represent a valid IPv4 or IPv6 address.

   >>> ipaddress.ip_address('192.168.0.1')
   IPv4Address('192.168.0.1')
   >>> ipaddress.ip_address('2001:db8::')
   IPv6Address('2001:db8::')

ipaddress.ip_network(address, strict=True)

   Return an "IPv4Network" or "IPv6Network" object depending on the IP
   address passed as argument.  *address* is a string or integer
   representing the IP network.  Either IPv4 or IPv6 networks may be
   supplied; integers less than "2**32" will be considered to be IPv4
   by default.  *strict* is passed to "IPv4Network" or "IPv6Network"
   constructor.  A "ValueError" is raised if *address* does not
   represent a valid IPv4 or IPv6 address, or if the network has host
   bits set.

   >>> ipaddress.ip_network('192.168.0.0/28')
   IPv4Network('192.168.0.0/28')

ipaddress.ip_interface(address)

   Return an "IPv4Interface" or "IPv6Interface" object depending on
   the IP address passed as argument.  *address* is a string or
   integer representing the IP address.  Either IPv4 or IPv6 addresses
   may be supplied; integers less than "2**32" will be considered to
   be IPv4 by default.  A "ValueError" is raised if *address* does not
   represent a valid IPv4 or IPv6 address.

これらの便利関数を利用するデメリットとして、IPv4 と IPv6 両方のフォー
マットを扱う必要性があるために、どちらを期待されていたのかを知ることが
できず、エラーメッセージが最小限の情報しか提供できないことです。利用し
たいバージョンの特定のコンストラクタを直接呼ぶことで、より詳細なエラー
レポートを得ることができます。


IP アドレス
===========


Address オブジェクト
--------------------

"IPv4Address" と "IPv6Address" オブジェクトは多くの共通した属性を持っ
ています。両方の IP バージョンを扱うコードを書きやすくするために、IPv6
アドレスでしか意味が無いいくつかの属性も "IPv4Address" オブジェクトに
実装されています。アドレスオブジェクトは *hashable* なので、辞書のキー
として利用できます。

class ipaddress.IPv4Address(address)

   IPv4 アドレスを構築する。 *address* が正しい IPv4 アドレスでない場
   合、 "AddressValueError" を発生させます。

   以下のものが正しい IPv4 アドレスを構築します:

   1. A string in decimal-dot notation, consisting of four decimal
      integers in the inclusive range 0--255, separated by dots (e.g.
      "192.168.0.1"). Each integer represents an octet (byte) in the
      address. Leading zeroes are not tolerated to prevent confusion
      with octal notation.

   2. 32bit に収まる整数。

   3. 大きさ4の "bytes" オブジェクトに (最上位オクテットが最初になるよ
      うに) パックされた整数。

   >>> ipaddress.IPv4Address('192.168.0.1')
   IPv4Address('192.168.0.1')
   >>> ipaddress.IPv4Address(3232235521)
   IPv4Address('192.168.0.1')
   >>> ipaddress.IPv4Address(b'\xC0\xA8\x00\x01')
   IPv4Address('192.168.0.1')

   バージョン 3.8 で変更: Leading zeros are tolerated, even in
   ambiguous cases that look like octal notation.

   バージョン 3.10 で変更: Leading zeros are no longer tolerated and
   are treated as an error. IPv4 address strings are now parsed as
   strict as glibc "inet_pton()".

   バージョン 3.9.5 で変更: The above change was also included in
   Python 3.9 starting with version 3.9.5.

   バージョン 3.8.12 で変更: The above change was also included in
   Python 3.8 starting with version 3.8.12.

   version

      適切なバージョン番号: IPv4 なら "4", IPv6 なら "6".

   max_prefixlen

      このバージョンのアドレスを表現するのに必要なビット数: IPv4 なら
      "32", IPv6 なら "128".

      prefix は、アドレスがネットワークに含まれるかどうかを決定するた
      めに比較する、アドレスの先頭ビット数を定義します。

   compressed

   exploded

      ドットと10進数を使った表現の文字列。この表現には先頭の 0 は含ま
      れません。

      IPv4 はアドレスの 0 オクテットを省略する記法を定義していないので
      、IPv4 アドレスにおいてこれらの2つの属性は常に "str(addr)" と等
      しくなります。これらの属性を用意することで、IPv4 と IPv6 アドレ
      ス両方を扱う、表示用コードが書きやすくなります。

   packed

      このアドレスのバイナリ表現 - 適切な長さをもった "bytes" オブジェ
      クト(最上位オクテットが先頭)。 IPv4 では 4 byte で、 IPv6 では
      16 byte。

   reverse_pointer

      The name of the reverse DNS PTR record for the IP address, e.g.:

         >>> ipaddress.ip_address("127.0.0.1").reverse_pointer
         '1.0.0.127.in-addr.arpa'
         >>> ipaddress.ip_address("2001:db8::1").reverse_pointer
         '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa'

      This is the name that could be used for performing a PTR lookup,
      not the resolved hostname itself.

      バージョン 3.5 で追加.

   is_multicast

      アドレスがマルチキャスト用に予約されている場合は "True" 。 **RFC
      3171** (IPv4) か **RFC 2373** (IPv6) を参照。

   is_private

      "True" if the address is defined as not globally reachable by
      iana-ipv4-special-registry (for IPv4) or iana-ipv6-special-
      registry (for IPv6) with the following exceptions:

      * "is_private" is "False" for the shared address space
        ("100.64.0.0/10")

      * For IPv4-mapped IPv6-addresses the "is_private" value is
        determined by the semantics of the underlying IPv4 addresses
        and the following condition holds (see
        "IPv6Address.ipv4_mapped"):

           address.is_private == address.ipv4_mapped.is_private

      "is_private" has value opposite to "is_global", except for the
      shared address space ("100.64.0.0/10" range) where they are both
      "False".

      バージョン 3.9.20 で変更: Fixed some false positives and false
      negatives.

      * "192.0.0.0/24" is considered private with the exception of
        "192.0.0.9/32" and "192.0.0.10/32" (previously: only the
        "192.0.0.0/29" sub-range was considered private).

      * "64:ff9b:1::/48" is considered private.

      * "2002::/16" is considered private.

      * There are exceptions within "2001::/23" (otherwise considered
        private): "2001:1::1/128", "2001:1::2/128", "2001:3::/32",
        "2001:4:112::/48", "2001:20::/28", "2001:30::/28". The
        exceptions are not considered private.

   is_global

      "True" if the address is defined as globally reachable by iana-
      ipv4-special-registry (for IPv4) or iana-ipv6-special-registry
      (for IPv6) with the following exception:

      For IPv4-mapped IPv6-addresses the "is_private" value is
      determined by the semantics of the underlying IPv4 addresses and
      the following condition holds (see "IPv6Address.ipv4_mapped"):

         address.is_global == address.ipv4_mapped.is_global

      "is_global" has value opposite to "is_private", except for the
      shared address space ("100.64.0.0/10" range) where they are both
      "False".

      バージョン 3.4 で追加.

      バージョン 3.9.20 で変更: Fixed some false positives and false
      negatives, see "is_private" for details.

   is_unspecified

      アドレスが未定義の時に "True". **RFC 5735** (IPv4) か **RFC
      2373** (IPv6) を参照。

   is_reserved

      IETF で予約されているアドレスの場合に "True"。

   is_loopback

      ループバックアドレスである場合に "True". **RFC 3330** (IPv4) か
      **RFC 2373** (IPv6) を参照。

   is_link_local

      アドレスがリンクローカル用に予約されいている場合に "True". **RFC
      3927** を参照。

IPv4Address.__format__(fmt)

   Returns a string representation of the IP address, controlled by an
   explicit format string. *fmt* can be one of the following: "'s'",
   the default option, equivalent to "str()", "'b'" for a zero-padded
   binary string, "'X'" or "'x'" for an uppercase or lowercase
   hexadecimal representation, or "'n'", which is equivalent to "'b'"
   for IPv4 addresses and "'x'" for IPv6. For binary and hexadecimal
   representations, the form specifier "'#'" and the grouping option
   "'_'" are available. "__format__" is used by "format", "str.format"
   and f-strings.

   >>> format(ipaddress.IPv4Address('192.168.0.1'))
   '192.168.0.1'
   >>> '{:#b}'.format(ipaddress.IPv4Address('192.168.0.1'))
   '0b11000000101010000000000000000001'
   >>> f'{ipaddress.IPv6Address("2001:db8::1000"):s}'
   '2001:db8::1000'
   >>> format(ipaddress.IPv6Address('2001:db8::1000'), '_X')
   '2001_0DB8_0000_0000_0000_0000_0000_1000'
   >>> '{:#_n}'.format(ipaddress.IPv6Address('2001:db8::1000'))
   '0x2001_0db8_0000_0000_0000_0000_0000_1000'

   バージョン 3.9 で追加.

class ipaddress.IPv6Address(address)

   IPv6 アドレスを構築する。 *address* が正しい IPv6 アドレスでない場
   合、 "AddressValueError" を発生させます。

   以下のものが正しい IPv6 アドレスを構築します:

   1. 4桁の16進数からなるグループ8個で構成された文字列。各グループは
      16bitを表現している。グループはコロンで区切られる。これは
      *exploded* (長い) 記法を表す。文字列は *compressed* (省略) 記法
      でも良い。詳細は **RFC 4291** を参照。例えば、
      ""0000:0000:0000:0000:0000:0abc:0007:0def"" は ""::abc:7:def""
      と省略できる。

      Optionally, the string may also have a scope zone ID, expressed
      with a suffix "%scope_id". If present, the scope ID must be non-
      empty, and may not contain "%". See **RFC 4007** for details.
      For example, "fe80::1234%1" might identify address "fe80::1234"
      on the first link of the node.

   2. 128bit に収まる整数。

   3. ビッグエンディアンで 16 バイトの長さの "bytes" オブジェクトにパ
      ックされた整数。

   >>> ipaddress.IPv6Address('2001:db8::1000')
   IPv6Address('2001:db8::1000')
   >>> ipaddress.IPv6Address('ff02::5678%1')
   IPv6Address('ff02::5678%1')

   compressed

   アドレス表現の短い形式で、グループ内の先頭の 0 を省略し、連続する完
   全に0のグループの一番長いシーケンスを1つの空グループに折りたたんだ
   もの。

   これは IPv6 アドレスに対して "str(addr)" が返す値と同じです。

   exploded

   アドレス表現の長い形式。全てのグループの先頭の0は省略されず、完全に
   0のグループも省略されない。

   以降の属性とメソッドについては、"IPv4Address" クラスの対応するドキ
   ュメントを参照してください:

   packed

   reverse_pointer

   version

   max_prefixlen

   is_multicast

   is_private

   is_global

   is_unspecified

   is_reserved

   is_loopback

   is_link_local

      バージョン 3.4 で追加: is_global

   is_site_local

      アドレスがサイトローカルな目的のために予約されいている場合に
      "True". サイトローカルアドレスは **RFC 3879** によって廃止されて
      いる事に注意してください。アドレスが **RFC 4193** で定義されてい
      るユニークローカルアドレスの範囲に含まれているかどうかをテストす
      るには、 "is_private" を利用してください。

   ipv4_mapped

      IPv4 にマップされた("::FFFF/96" で始まる)アドレスの場合、このプ
      ロパティは埋め込まれた IPv4 Address を返します。それ以外のアドレ
      スに対しては、このプロパティは "None" になります。

   scope_id

      For scoped addresses as defined by **RFC 4007**, this property
      identifies the particular zone of the address's scope that the
      address belongs to, as a string. When no scope zone is
      specified, this property will be "None".

   sixtofour

      **RFC 3056** で定義された 6to4 ("2002::/16" で始まる)アドレスの
      場合、このプロパティは埋め込まれた IPv4 Address を返します。それ
      以外のアドレスに対しては、このプロパティは "None" になります。

   teredo

      **RFC 4380** で定義された Teredo ("2001::/32" で始まる)アドレス
      の場合、このプロパティは埋め込まれた "(server, client)" IP アド
      レスペアを返します。それ以外のアドレスに対しては、このプロパティ
      は "None" になります。

IPv6Address.__format__(fmt)

   "IPv4Address" の対応するメソッドのドキュメントを参照してください。

   バージョン 3.9 で追加.


文字列と整数への変換
--------------------

socket モジュールなどのネットワークインターフェースを利用するには、ア
ドレスを文字列や整数に変換しなければなりません。これには組み込みの
"str()" と "int()" 関数を利用します:

   >>> str(ipaddress.IPv4Address('192.168.0.1'))
   '192.168.0.1'
   >>> int(ipaddress.IPv4Address('192.168.0.1'))
   3232235521
   >>> str(ipaddress.IPv6Address('::1'))
   '::1'
   >>> int(ipaddress.IPv6Address('::1'))
   1

Note that IPv6 scoped addresses are converted to integers without
scope zone ID.


演算子
------

Address オブジェクトはいくつかの演算子をサポートします。明記されない限
り、演算子は互換性のあるオブジェクト間 (つまり IPv4 同士や IPv6 同士)
でのみ利用できます。


比較演算子
~~~~~~~~~~

Address objects can be compared with the usual set of comparison
operators. Same IPv6 addresses with different scope zone IDs are not
equal. Some examples:

   >>> IPv4Address('127.0.0.2') > IPv4Address('127.0.0.1')
   True
   >>> IPv4Address('127.0.0.2') == IPv4Address('127.0.0.1')
   False
   >>> IPv4Address('127.0.0.2') != IPv4Address('127.0.0.1')
   True
   >>> IPv6Address('fe80::1234') == IPv6Address('fe80::1234%1')
   False
   >>> IPv6Address('fe80::1234%1') != IPv6Address('fe80::1234%2')
   True


算術演算
~~~~~~~~

アドレスオブジェクトから整数を加減算できます。いくつかの例:

   >>> IPv4Address('127.0.0.2') + 3
   IPv4Address('127.0.0.5')
   >>> IPv4Address('127.0.0.2') - 3
   IPv4Address('126.255.255.255')
   >>> IPv4Address('255.255.255.255') + 1
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
   ipaddress.AddressValueError: 4294967296 (>= 2**32) is not permitted as an IPv4 address


IP ネットワーク定義
===================

"IPv4Network" と "IPv6Network" オブジェクトは IP ネットワークの定義と
インスペクトのための機構を提供します。ネットワーク定義は *mask* と *ネ
ットワークアドレス* からなり、 *mask* でマスク(bitごとの AND) するとネ
ットワークアドレスと同じになる IP アドレスの範囲を定義します。例えば、
"255.255.255.0" という *mask* と "192.168.1.0" というネットワークアド
レスからなるネットワーク定義は、 "192.168.1.0" から "192.168.1.255" を
含む範囲を表します。


プリフィックス, ネットマスク、ホストマスク
------------------------------------------

IP ネットワークマスクを定義する幾つかの等価な方法があります。*プリフィ
ックス* "/<nbits>" は先頭の何bitがネットワークマスクで立っているかを示
します。*ネットマスク* は先頭の幾つかのbitが立っている IP アドレスです
。プリフィックス "/24" はIPv4 ではネットマスク "255.255.255.0" と、
IPv6 では "ffff:ff00::" と同じになります。加えて、*ネットマスク* と論
理が逆の *ホストマスク* があり、ときどき (例えば Cisco のアクセスコン
トロールリスト) ネットワークマスクを表すために利用されます。"/24" と等
しい IPv4 のホストマスクは "0.0.0.255" になります。


Network オブジェクト
--------------------

address オブジェクトで実装されていた属性は全て network オブジェクトに
も実装されています。 network はそれに追加で幾つかの属性を実装していま
す。 全ての追加属性は "IPv4Network" と "IPv6Network" で共通なので、重
複を避けるために "IPv4Network" にだけドキュメントされています。ネット
ワークオブジェクトは *hashable* なので、辞書のキーとして使用できます。

class ipaddress.IPv4Network(address, strict=True)

   IPv4 ネットワーク定義を構築します。*address* は以下の1つです:

   1. IPアドレスと、オプションでスラッシュ ("/") で区切られたマスクを
      持つ文字列。IPアドレスはネットワークアドレスで、マスクは *プリフ
      ィックス* を意味する1つの数値か、 IPv4 アドレスの文字列表現です
      。マスクがIPv4アドレスのとき、非ゼロのフィールドで始まるときは *
      ネットマスク* として、ゼロのフィールドで始まるときは *ホストマス
      ク* として解釈されます。ただし、すべてのフィールドが0の場合は、
      >>*<<ネットマスク*として扱われます。マスクが省略された場合、
      "/32" が指定されたものとします。

      例えば、次の *address* 指定は全て等しくなります:
      "192.168.1.0/24", "192.168.1.0/255.255.255.0"
      "192.168.1.0/0.0.0.255".

   2. 32bit に収まる整数。これは1つのアドレスのネットワークと等しく、
      ネットワークアドレスが *address* に、マスクが "/32" になります。

   3. 4byte の "bytes" オブジェクトにビッグエンディアンでパックされた
      整数。これは整数の *address* と同じように解釈されます。

   4. アドレス記述とネットマスクの2要素のタプル。アドレス記述は、文字
      列、32ビットの整数、4バイトのパックされた整数、 既存の
      IPv4Address オブジェクトのいずれかです。ネットマスクは、プレフィ
      ックス長を表す整数（例えば `` 24``）またはプレフィックスマスクを
      表す文字列（例えば `` 255.255.255.0``）です。

   *address* が有効な IPv4 アドレスでない場合に "AddressValueError" 例
   外を発生させます。マスクが IPv4 アドレスに対して有効でない場合に
   "NetmaskValueError" 例外を発生させます。

   *strict* が "True" の場合、与えられたアドレスのホストビットが立って
   いたら "ValueError" を発生させます。そうでない場合、ホストビットを
   マスクして正しいネットワークアドレスを計算します。

   特に明記されない場合、他の network や address を受け取る network の
   メソッドは、引数の IP バージョンが "self" と異なる場合に
   "TypeError" を発生させます。

   バージョン 3.5 で変更: *address* コンストラクタ引数に2要素のタプル
   形式を追加しました

   version

   max_prefixlen

      "IPv4Address" の対応する属性のドキュメントを参照してください。

   is_multicast

   is_private

   is_unspecified

   is_reserved

   is_loopback

   is_link_local

      These attributes are true for the network as a whole if they are
      true for both the network address and the broadcast address.

   network_address

      この network のネットワークアドレス。ネットワークアドレスとプリ
      フィックス長によってユニークにネットワークが定義されます。

   broadcast_address

      このネットワークのブロードキャストアドレス。ブロードキャストアド
      レスに投げられたパケットはそのネットワーク内の全てのホストに受信
      されます。

   hostmask

      "IPv4Address" オブジェクトとして表現された ホストマスク。

   netmask

      "IPv4Address" オブジェクトとして表現された ネットマスク。

   with_prefixlen

   compressed

   exploded

      A string representation of the network, with the mask in prefix
      notation.

      "with_prefixlen" and "compressed" are always the same as
      "str(network)". "exploded" uses the exploded form the network
      address.

   with_netmask

      A string representation of the network, with the mask in net
      mask notation.

   with_hostmask

      A string representation of the network, with the mask in host
      mask notation.

   num_addresses

      ネットワーク内のアドレスの総数

   prefixlen

      ネットワークプレフィックスのビット長。

   hosts()

      Returns an iterator over the usable hosts in the network.  The
      usable hosts are all the IP addresses that belong to the
      network, except the network address itself and the network
      broadcast address.  For networks with a mask length of 31, the
      network address and network broadcast address are also included
      in the result. Networks with a mask of 32 will return a list
      containing the single host address.

      >>> list(ip_network('192.0.2.0/29').hosts())  
      [IPv4Address('192.0.2.1'), IPv4Address('192.0.2.2'),
       IPv4Address('192.0.2.3'), IPv4Address('192.0.2.4'),
       IPv4Address('192.0.2.5'), IPv4Address('192.0.2.6')]
      >>> list(ip_network('192.0.2.0/31').hosts())
      [IPv4Address('192.0.2.0'), IPv4Address('192.0.2.1')]
      >>> list(ip_network('192.0.2.1/32').hosts())
      [IPv4Address('192.0.2.1')]

   overlaps(other)

      "True" if this network is partly or wholly contained in *other*
      or *other* is wholly contained in this network.

   address_exclude(network)

      Computes the network definitions resulting from removing the
      given *network* from this one.  Returns an iterator of network
      objects. Raises "ValueError" if *network* is not completely
      contained in this network.

      >>> n1 = ip_network('192.0.2.0/28')
      >>> n2 = ip_network('192.0.2.1/32')
      >>> list(n1.address_exclude(n2))  
      [IPv4Network('192.0.2.8/29'), IPv4Network('192.0.2.4/30'),
       IPv4Network('192.0.2.2/31'), IPv4Network('192.0.2.0/32')]

   subnets(prefixlen_diff=1, new_prefix=None)

      The subnets that join to make the current network definition,
      depending on the argument values.  *prefixlen_diff* is the
      amount our prefix length should be increased by.  *new_prefix*
      is the desired new prefix of the subnets; it must be larger than
      our prefix.  One and only one of *prefixlen_diff* and
      *new_prefix* must be set.  Returns an iterator of network
      objects.

      >>> list(ip_network('192.0.2.0/24').subnets())
      [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/25')]
      >>> list(ip_network('192.0.2.0/24').subnets(prefixlen_diff=2))  
      [IPv4Network('192.0.2.0/26'), IPv4Network('192.0.2.64/26'),
       IPv4Network('192.0.2.128/26'), IPv4Network('192.0.2.192/26')]
      >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=26))  
      [IPv4Network('192.0.2.0/26'), IPv4Network('192.0.2.64/26'),
       IPv4Network('192.0.2.128/26'), IPv4Network('192.0.2.192/26')]
      >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=23))
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
          raise ValueError('new prefix must be longer')
      ValueError: new prefix must be longer
      >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=25))
      [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/25')]

   supernet(prefixlen_diff=1, new_prefix=None)

      The supernet containing this network definition, depending on
      the argument values.  *prefixlen_diff* is the amount our prefix
      length should be decreased by.  *new_prefix* is the desired new
      prefix of the supernet; it must be smaller than our prefix.  One
      and only one of *prefixlen_diff* and *new_prefix* must be set.
      Returns a single network object.

      >>> ip_network('192.0.2.0/24').supernet()
      IPv4Network('192.0.2.0/23')
      >>> ip_network('192.0.2.0/24').supernet(prefixlen_diff=2)
      IPv4Network('192.0.0.0/22')
      >>> ip_network('192.0.2.0/24').supernet(new_prefix=20)
      IPv4Network('192.0.0.0/20')

   subnet_of(other)

      このネットワークが *other* のサブネットの場合に "True" を返しま
      す。

      >>> a = ip_network('192.168.1.0/24')
      >>> b = ip_network('192.168.1.128/30')
      >>> b.subnet_of(a)
      True

      バージョン 3.7 で追加.

   supernet_of(other)

      このネットワークが *other* のスーパーネットの場合に "True" を返
      します。

      >>> a = ip_network('192.168.1.0/24')
      >>> b = ip_network('192.168.1.128/30')
      >>> a.supernet_of(b)
      True

      バージョン 3.7 で追加.

   compare_networks(other)

      このネットワークを *other* と比較します。比較ではネットワークア
      ドレスのみが考慮され、ホストアドレスは考慮されません。"-1"、"0"
      、"1" のいずれかを返します。

      >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.2/32'))
      -1
      >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.0/32'))
      1
      >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.1/32'))
      0

      バージョン 3.7 で非推奨: It uses the same ordering and
      comparison algorithm as "<", "==", and ">"

class ipaddress.IPv6Network(address, strict=True)

   IPv6 ネットワーク定義を構築します。*address* は以下の1つです:

   1. A string consisting of an IP address and an optional prefix
      length, separated by a slash ("/").  The IP address is the
      network address, and the prefix length must be a single number,
      the *prefix*.  If no prefix length is provided, it's considered
      to be "/128".

      Note that currently expanded netmasks are not supported.  That
      means "2001:db00::0/24" is a valid argument while
      "2001:db00::0/ffff:ff00::" is not.

   2. 128bit に収まる整数。これは1つのアドレスのネットワークと等しく、
      ネットワークアドレスが *address* に、マスクが "/128" になります
      。

   3. 16byte の "bytes" オブジェクトにビッグエンディアンでパックされた
      整数。これは整数の *address* と同じように解釈されます。

   4. アドレス記述とネットマスクの2要素のタプル。アドレス記述は、文字
      列、128ビットの整数、16バイトのパックされた整数、 既存の
      IPv6Address オブジェクトのいずれかです。ネットマスクは、プレフィ
      ックス長を表す整数です。

   *address* が有効な IPv6 アドレスでない場合に "AddressValueError" 例
   外を発生させます。マスクが IPv6 アドレスに対して有効でない場合に
   "NetmaskValueError" 例外を発生させます。

   *strict* が "True" の場合、与えられたアドレスのホストビットが立って
   いたら "ValueError" を発生させます。そうでない場合、ホストビットを
   マスクして正しいネットワークアドレスを計算します。

   バージョン 3.5 で変更: *address* コンストラクタ引数に2要素のタプル
   形式を追加しました

   version

   max_prefixlen

   is_multicast

   is_private

   is_unspecified

   is_reserved

   is_loopback

   is_link_local

   network_address

   broadcast_address

   hostmask

   netmask

   with_prefixlen

   compressed

   exploded

   with_netmask

   with_hostmask

   num_addresses

   prefixlen

   hosts()

      Returns an iterator over the usable hosts in the network.  The
      usable hosts are all the IP addresses that belong to the
      network, except the Subnet-Router anycast address.  For networks
      with a mask length of 127, the Subnet-Router anycast address is
      also included in the result. Networks with a mask of 128 will
      return a list containing the single host address.

   overlaps(other)

   address_exclude(network)

   subnets(prefixlen_diff=1, new_prefix=None)

   supernet(prefixlen_diff=1, new_prefix=None)

   subnet_of(other)

   supernet_of(other)

   compare_networks(other)

      "IPv4Network" の対応する属性のドキュメントを参照してください。

   is_site_local

      These attribute is true for the network as a whole if it is true
      for both the network address and the broadcast address.


演算子
------

Network オブジェクトはいくつかの演算子をサポートします。明記されない限
り、演算子は互換性のあるオブジェクト間 (つまり IPv4 同士や IPv6 同士)
でのみ利用できます。


論理演算子
~~~~~~~~~~

Network objects can be compared with the usual set of logical
operators. Network objects are ordered first by network address, then
by net mask.


イテレーション
~~~~~~~~~~~~~~

Network objects can be iterated to list all the addresses belonging to
the network.  For iteration, *all* hosts are returned, including
unusable hosts (for usable hosts, use the "hosts()" method).  An
example:

   >>> for addr in IPv4Network('192.0.2.0/28'):
   ...     addr
   ...
   IPv4Address('192.0.2.0')
   IPv4Address('192.0.2.1')
   IPv4Address('192.0.2.2')
   IPv4Address('192.0.2.3')
   IPv4Address('192.0.2.4')
   IPv4Address('192.0.2.5')
   IPv4Address('192.0.2.6')
   IPv4Address('192.0.2.7')
   IPv4Address('192.0.2.8')
   IPv4Address('192.0.2.9')
   IPv4Address('192.0.2.10')
   IPv4Address('192.0.2.11')
   IPv4Address('192.0.2.12')
   IPv4Address('192.0.2.13')
   IPv4Address('192.0.2.14')
   IPv4Address('192.0.2.15')


アドレスのコンテナとしてのネットワーク
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ネットワークオブジェクトは、アドレスのコンテナとして振舞えます。いくつ
か例をあげます:

   >>> IPv4Network('192.0.2.0/28')[0]
   IPv4Address('192.0.2.0')
   >>> IPv4Network('192.0.2.0/28')[15]
   IPv4Address('192.0.2.15')
   >>> IPv4Address('192.0.2.6') in IPv4Network('192.0.2.0/28')
   True
   >>> IPv4Address('192.0.3.6') in IPv4Network('192.0.2.0/28')
   False


インターフェイスオブジェクト
============================

インターフェースオブジェクトは *hashable* なので、辞書のキーとして使用
できます。

class ipaddress.IPv4Interface(address)

   Construct an IPv4 interface.  The meaning of *address* is as in the
   constructor of "IPv4Network", except that arbitrary host addresses
   are always accepted.

   "IPv4Interface" is a subclass of "IPv4Address", so it inherits all
   the attributes from that class.  In addition, the following
   attributes are available:

   ip

      The address ("IPv4Address") without network information.

      >>> interface = IPv4Interface('192.0.2.5/24')
      >>> interface.ip
      IPv4Address('192.0.2.5')

   network

      The network ("IPv4Network") this interface belongs to.

      >>> interface = IPv4Interface('192.0.2.5/24')
      >>> interface.network
      IPv4Network('192.0.2.0/24')

   with_prefixlen

      A string representation of the interface with the mask in prefix
      notation.

      >>> interface = IPv4Interface('192.0.2.5/24')
      >>> interface.with_prefixlen
      '192.0.2.5/24'

   with_netmask

      A string representation of the interface with the network as a
      net mask.

      >>> interface = IPv4Interface('192.0.2.5/24')
      >>> interface.with_netmask
      '192.0.2.5/255.255.255.0'

   with_hostmask

      A string representation of the interface with the network as a
      host mask.

      >>> interface = IPv4Interface('192.0.2.5/24')
      >>> interface.with_hostmask
      '192.0.2.5/0.0.0.255'

class ipaddress.IPv6Interface(address)

   Construct an IPv6 interface.  The meaning of *address* is as in the
   constructor of "IPv6Network", except that arbitrary host addresses
   are always accepted.

   "IPv6Interface" is a subclass of "IPv6Address", so it inherits all
   the attributes from that class.  In addition, the following
   attributes are available:

   ip

   network

   with_prefixlen

   with_netmask

   with_hostmask

      "IPv4Interface" の対応する属性のドキュメントを参照してください。


演算子
------

Interface オブジェクトはいくつかの演算子をサポートします。明記されない
限り、演算子は互換性のあるオブジェクト間 (つまり IPv4 同士や IPv6 同士
) でのみ利用できます。


論理演算子
~~~~~~~~~~

Interface objects can be compared with the usual set of logical
operators.

For equality comparison ("==" and "!="), both the IP address and
network must be the same for the objects to be equal.  An interface
will not compare equal to any address or network object.

For ordering ("<", ">", etc) the rules are different.  Interface and
address objects with the same IP version can be compared, and the
address objects will always sort before the interface objects.  Two
interface objects are first compared by their networks and, if those
are the same, then by their IP addresses.


その他のモジュールレベル関数
============================

このモジュールは以下のモジュールレベル関数も提供しています:

ipaddress.v4_int_to_packed(address)

   アドレスをネットワークバイトオーダー(ビッグエンディアン)でパックさ
   れた4バイトで表現します。 *address* は IPv4 IPアドレスを整数で表し
   たものです。整数が負だったり IPv4 IPアドレスとして大きすぎる場合は
   "ValueError" 例外を発生させます。

   >>> ipaddress.ip_address(3221225985)
   IPv4Address('192.0.2.1')
   >>> ipaddress.v4_int_to_packed(3221225985)
   b'\xc0\x00\x02\x01'

ipaddress.v6_int_to_packed(address)

   アドレスをネットワークバイトオーダー(ビッグエンディアン)でパックさ
   れた16バイトで表現します。 *address* は IPv6 IPアドレスを整数で表し
   たものです。整数が負だったり IPv6 IPアドレスとして大きすぎる場合は
   "ValueError" 例外を発生させます。

ipaddress.summarize_address_range(first, last)

   first と last で指定された IPアドレス帯に対するイテレーターを返しま
   す。 *first* はアドレス帯の中の最初の "IPv4Address" か
   "IPv6Address" で、 *last* はアドレス帯の中の最後の  "IPv4Address"
   か "IPv6Address" です。 *first* か *last* がIPアドレスでない場合や
   、2つの型が揃っていない場合に、 "TypeError" を発生させます。 *last*
   が *first* より大きくない場合や、 *first* アドレスのバージョンが 4
   でも 6 でもない場合は "ValueError" を発生させます。

   >>> [ipaddr for ipaddr in ipaddress.summarize_address_range(
   ...    ipaddress.IPv4Address('192.0.2.0'),
   ...    ipaddress.IPv4Address('192.0.2.130'))]
   [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/31'), IPv4Network('192.0.2.130/32')]

ipaddress.collapse_addresses(addresses)

   Return an iterator of the collapsed "IPv4Network" or "IPv6Network"
   objects.  *addresses* is an iterator of "IPv4Network" or
   "IPv6Network" objects.  A "TypeError" is raised if *addresses*
   contains mixed version objects.

   >>> [ipaddr for ipaddr in
   ... ipaddress.collapse_addresses([ipaddress.IPv4Network('192.0.2.0/25'),
   ... ipaddress.IPv4Network('192.0.2.128/25')])]
   [IPv4Network('192.0.2.0/24')]

ipaddress.get_mixed_type_key(obj)

   ネットワークとアドレスをソートするための key 関数を返します。アドレ
   スとネットワークは本質的に違うものなので、デフォルトでは比較できま
   せん。そのため、次の式は:

      IPv4Address('192.0.2.0') <= IPv4Network('192.0.2.0/24')

   理にかなっていません。しかし、それでも "ipaddress" にそれらをソート
   してほしい場合があるかもしれません。その場合は、この関数を
   "sorted()" の *key* 引数に使うことができます。

   *obj* はネットワークオブジェクトかアドレスオブジェクトのどちらかで
   す。


Custom Exceptions
=================

クラスのコンストラクタがより具体的なエラー報告をするために、このモジュ
ールでは以下の例外を定義します:

exception ipaddress.AddressValueError(ValueError)

   Any value error related to the address.

exception ipaddress.NetmaskValueError(ValueError)

   Any value error related to the net mask.
