Exemple #1
0
	def test_cidr_create_ipv4(self):
		self.assertEqual(str(IPAddress.create_cidr_subnet(32)), "255.255.255.255")
		self.assertEqual(str(IPAddress.create_cidr_subnet(24)), "255.255.255.0")
		self.assertEqual(str(IPAddress.create_cidr_subnet(16)), "255.255.0.0")
		self.assertEqual(str(IPAddress.create_cidr_subnet(10)), "255.192.0.0")
		self.assertEqual(str(IPAddress.create_cidr_subnet(8)), "255.0.0.0")
		self.assertEqual(str(IPAddress.create_cidr_subnet(1)), "128.0.0.0")
		self.assertEqual(str(IPAddress.create_cidr_subnet(0)), "0.0.0.0")
Exemple #2
0
	def test_subnet_malformed(self):
		with self.assertRaises(InvalidIPAddressException):
			IPAddressSubnet(IPAddress(range(4)), IPAddress(range(16)))
Exemple #3
0
	def test_malformed(self):
		with self.assertRaises(InvalidIPAddressException):
			IPAddress(bytes.fromhex("aa bb cc"))
Exemple #4
0
	def test_ipv6_shortabbr6(self):
		ip = IPAddress(bytes.fromhex("0000 0000 0000 0000 0000 0000 0000 0000"))
		self.assertEqual(str(ip), "::")
Exemple #5
0
	def test_ipv6_shortabbr4(self):
		ip = IPAddress(bytes.fromhex("1122 0000 0000 0000 0000 0000 0000 5566"))
		self.assertEqual(str(ip), "1122::5566")
Exemple #6
0
	def test_ipv6_shortlead(self):
		ip = IPAddress(bytes.fromhex("01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 00 0f"))
		self.assertEqual(str(ip), "102:304:506:708:90a:b0c:d0e:f")
Exemple #7
0
	def test_ipv6(self):
		ip = IPAddress(bytes.fromhex("aa bb cc dd 1a 1b 1c 1d 2a 2b 2c 2d 3a 3b 3c 3d"))
		self.assertEqual(str(ip), "aabb:ccdd:1a1b:1c1d:2a2b:2c2d:3a3b:3c3d")
		self.assertEqual(int(ip), 0xaabbccdd1a1b1c1d2a2b2c2d3a3b3c3d)
Exemple #8
0
	def test_ipv4(self):
		ip = IPAddress(bytes.fromhex("aa bb cc dd"))
		self.assertEqual(str(ip), "170.187.204.221")
		self.assertEqual(int(ip), 0xaabbccdd)
Exemple #9
0
	def test_cidr_contained(self):
		self.assertTrue(IPAddressSubnet.from_str("192.168.1.0/24").contains_ip(IPAddress.from_str("192.168.1.123")))
		self.assertTrue(IPAddressSubnet.from_str("192.168.1.0/24").contains_ip(IPAddress.from_str("192.168.1.0")))
		self.assertTrue(IPAddressSubnet.from_str("192.168.1.0/24").contains_ip(IPAddress.from_str("192.168.1.255")))
		self.assertFalse(IPAddressSubnet.from_str("192.168.1.0/24").contains_ip(IPAddress.from_str("192.168.2.255")))