MCPcopy
hub / github.com/Xyntax/POC-T / overlaps

Method overlaps

thirdparty/IPy/IPy.py:655–678  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

653
654
655 def overlaps(self, item):
656 """Check if two IP address ranges overlap.
657
658 Returns 0 if the two ranges don't overlap, 1 if the given
659 range overlaps at the end and -1 if it does at the beginning.
660
661 >>> IP('192.168.0.0/23').overlaps('192.168.1.0/24')
662 1
663 >>> IP('192.168.0.0/23').overlaps('192.168.1.255')
664 1
665 >>> IP('192.168.0.0/23').overlaps('192.168.2.0')
666 0
667 >>> IP('192.168.1.0/24').overlaps('192.168.0.0/23')
668 -1
669 """
670
671 if not isinstance(item, IP):
672 item = IP(item)
673 if item.ip >= self.ip and item.ip < self.ip + self.len():
674 return 1
675 elif self.ip >= item.ip and self.ip < item.ip + item.len():
676 return -1
677 else:
678 return 0
679
680
681 def __str__(self):

Callers

nothing calls this directly

Calls 2

lenMethod · 0.95
IPClass · 0.85

Tested by

no test coverage detected