用法:
subnets(prefixlen_diff=1, new_prefix=None)
加入的子網以創建當前網絡定義,具體取決於參數值。
prefixlen_diff
是我們的前綴長度應該增加的數量。new_prefix
是子網所需的新前綴;它必須大於我們的前綴。必須設置prefixlen_diff
和new_prefix
中的一項且僅一項。返回網絡對象的迭代器。>>> 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')]
相關用法
- Python ipaddress.IPv4Network.subnet_of用法及代碼示例
- Python ipaddress.IPv4Network.supernet用法及代碼示例
- Python ipaddress.IPv4Network.supernet_of用法及代碼示例
- Python ipaddress.IPv4Network.address_exclude用法及代碼示例
- Python ipaddress.IPv4Network.compare_networks用法及代碼示例
- Python ipaddress.IPv4Network.hosts用法及代碼示例
- Python ipaddress.IPv4Address.reverse_pointer用法及代碼示例
- Python ipaddress.IPv4Address.__format__用法及代碼示例
- Python ipaddress.IPv4Interface.ip用法及代碼示例
- Python ipaddress.IPv4Interface.with_prefixlen用法及代碼示例
- Python ipaddress.IPv4Interface.with_netmask用法及代碼示例
- Python ipaddress.IPv4Interface.with_hostmask用法及代碼示例
- Python ipaddress.IPv4Address用法及代碼示例
- Python ipaddress.IPv4Interface.network用法及代碼示例
- Python ipaddress.IPv6Address用法及代碼示例
- Python ipaddress.collapse_addresses用法及代碼示例
- Python ipaddress.summarize_address_range用法及代碼示例
- Python ipaddress.v4_int_to_packed用法及代碼示例
- Python ipaddress.ip_address用法及代碼示例
- Python numpy ipmt用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 ipaddress.IPv4Network.subnets。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。