Check if two IP address ranges overlap. Returns 0 if the two ranges don't overlap, 1 if the given range overlaps at the end and -1 if it does at the beginning. >>> IP('192.168.0.0/23').overlaps('192.168.1.0/24') 1 >>> IP('192.168.0.0/23').overlaps('192.168.1
(self, item)
| 584 | |
| 585 | |
| 586 | def overlaps(self, item): |
| 587 | """Check if two IP address ranges overlap. |
| 588 | |
| 589 | Returns 0 if the two ranges don't overlap, 1 if the given |
| 590 | range overlaps at the end and -1 if it does at the beginning. |
| 591 | |
| 592 | >>> IP('192.168.0.0/23').overlaps('192.168.1.0/24') |
| 593 | 1 |
| 594 | >>> IP('192.168.0.0/23').overlaps('192.168.1.255') |
| 595 | 1 |
| 596 | >>> IP('192.168.0.0/23').overlaps('192.168.2.0') |
| 597 | 0 |
| 598 | >>> IP('192.168.1.0/24').overlaps('192.168.0.0/23') |
| 599 | -1 |
| 600 | """ |
| 601 | |
| 602 | item = IP(item) |
| 603 | if item.ip >= self.ip and item.ip < self.ip + self.len(): |
| 604 | return 1 |
| 605 | elif self.ip >= item.ip and self.ip < item.ip + item.len(): |
| 606 | return -1 |
| 607 | else: |
| 608 | return 0 |
| 609 | |
| 610 | |
| 611 | def __str__(self): |