예제 #1
0
 def start(self):
     if self.cidr_prefix_length is not None:
         start, end = ipu.cidr_to_range(self.first_ip,
                                        self.cidr_prefix_length)
         return start
     else:
         return ipu.to_number(self.first_ip)
예제 #2
0
 def end(self):
     if self.last_ip is not None:
         return ipu.to_number(self.last_ip)
     if self.cidr_prefix_length is not None:
         start, end = ipu.cidr_to_range(self.first_ip,
                                        self.cidr_prefix_length)
         return end
     return self.start
예제 #3
0
    def test_ip_to_number_conversions_ipv6(self):
        self.assertEqual(1, ipu.to_number('0:0:0:0:0:0:0:1'))
        self.assertEqual(10, ipu.to_number('0:0:0:0:0:0:0:a'))
        self.assertEqual((2 ** 16) ** 7 + 10, ipu.to_number('1:0:0:0:0:0:0:a'))

        # Zero collapse syntax
        self.assertEqual(0, ipu.to_number('::'))
        self.assertEqual(1, ipu.to_number('::1'))
        self.assertEqual((2 ** 16) ** 7 + 10, ipu.to_number('1::a'))

        # Mixed syntax
        self.assertEqual(1, ipu.to_number('::0.0.0.1'))
        self.assertEqual((2 ** 16) ** 7 + 10, ipu.to_number('1::0.0.0.10'))
예제 #4
0
 def __contains__(self, ip):
     ip_nr = ipu.to_number(ip)
     return self.start <= ip_nr <= self.end 
예제 #5
0
 def test_ip_to_number_conversions(self):
     self.assertEqual(0, ipu.to_number('0.0.0.0'))
     self.assertEqual(1, ipu.to_number('0.0.0.1'))
     self.assertEqual(256, ipu.to_number('0.0.1.0'))
     self.assertEqual(65537, ipu.to_number('0.1.0.1'))
     self.assertEqual(16842753, ipu.to_number('1.1.0.1'))
예제 #6
0
 def test_ip_to_number_conversions_ipv6(self):
     self.assertEqual(0, ipu.to_number('::'))
예제 #7
0
 def test_ip_to_number_conversions(self):
     self.assertEqual(0, ipu.to_number('0.0.0.0'))
     self.assertEqual(1, ipu.to_number('0.0.0.1'))
     self.assertEqual(256, ipu.to_number('0.0.1.0'))
     self.assertEqual(65537, ipu.to_number('0.1.0.1'))
     self.assertEqual(16842753, ipu.to_number('1.1.0.1'))