Return the length of a subnet. >>> print IP('195.185.1.0/28').len() 16 >>> print IP('195.185.1.0/24').len() 256
(self)
| 490 | raise ValueError, "only IPv4 and IPv6 supported" |
| 491 | |
| 492 | def len(self): |
| 493 | """Return the length of a subnet. |
| 494 | |
| 495 | >>> print IP('195.185.1.0/28').len() |
| 496 | 16 |
| 497 | >>> print IP('195.185.1.0/24').len() |
| 498 | 256 |
| 499 | """ |
| 500 | |
| 501 | if self._ipversion == 4: |
| 502 | locallen = 32 - self._prefixlen |
| 503 | elif self._ipversion == 6: |
| 504 | locallen = 128 - self._prefixlen |
| 505 | else: |
| 506 | raise ValueError, "only IPv4 and IPv6 supported" |
| 507 | |
| 508 | return 2L ** locallen |
| 509 | |
| 510 | |
| 511 | def __nonzero__(self): |
no outgoing calls
no test coverage detected