openc2lib.types.targets.ipv6_net

 1import ipaddress
 2
 3from openc2lib.core.target import target
 4
 5@target('ipv6_net')
 6class IPv6Net:
 7	"""OpenC2 IPv6 Address Range
 8		
 9		IPv6 Address Range as defined in Sec. 3.4.1.9.
10
11		The Standard is not clear on this part. The 
12		IPv6Net Target is defined as "Array /ipv6-net"
13		(where ipv6-net --lowercase!-- is never defined!)
14		However, the json serialization requirements explicitely
15		define:
16		Array /ipv6-net: JSON string containing the text representation 
17		 						of an IPv6 address range as specified in 
18		 						[RFC4291], Section 2.3.
19		According to this definition, I assume a single network address
20		should be managed. Extension to an array of IP network addresses
21		is rather straightforward by using a list for ipv6_net attribute.
22		Note that I have to keep both the string representation of the
23		network address as well as the IPv6Network object to easily 
24		manage the code and to automate the creation of the dictionary.
25		
26	"""
27	
28	def __init__(self, ipv6_net=None, prefix=None):
29		""" Initialize IPv6 Address Range
30
31			Initialize `IPv6Net with IPv6 address and prefix.
32			If no IPv6 address is given, initialize to null address.
33			If no prefix is given, assume /128 (IPv6 address only).
34			:param ipv6_net: IPv6 Network Address.
35			:param prefix: IPv6 Network Adress Prefix.
36		"""
37		if ipv6_net is None:
38		    net = ipaddress.IPv6Network("::/0")
39		elif prefix is None:
40		    net = ipaddress.IPv6Network(ipv6_net)
41		else:
42		    tmp = ipv6_net + "/" + str(prefix)
43		    net = ipaddress.IPv6Network(tmp)
44
45		self.__ipv6_net = net.exploded
46	
47	def addr(self):
48		""" Returns address part only (no prefix) """
49		return ipaddress.IPv6Network(self.__ipv6_net).network_address.exploded
50	
51	def prefix(self):
52		""" Returns prefix only """
53		return ipaddress.IPv6Network(self.__ipv6_net).prefixlen
54	
55	def __str__(self):
56	    return ipaddress.IPv6Network(self.__ipv6_net).exploded
57	
58	def __repr__(self):
59	    return ipaddress.IPv6Network(self.__ipv6_net).exploded
@target('ipv6_net')
class IPv6Net:
 6@target('ipv6_net')
 7class IPv6Net:
 8	"""OpenC2 IPv6 Address Range
 9		
10		IPv6 Address Range as defined in Sec. 3.4.1.9.
11
12		The Standard is not clear on this part. The 
13		IPv6Net Target is defined as "Array /ipv6-net"
14		(where ipv6-net --lowercase!-- is never defined!)
15		However, the json serialization requirements explicitely
16		define:
17		Array /ipv6-net: JSON string containing the text representation 
18		 						of an IPv6 address range as specified in 
19		 						[RFC4291], Section 2.3.
20		According to this definition, I assume a single network address
21		should be managed. Extension to an array of IP network addresses
22		is rather straightforward by using a list for ipv6_net attribute.
23		Note that I have to keep both the string representation of the
24		network address as well as the IPv6Network object to easily 
25		manage the code and to automate the creation of the dictionary.
26		
27	"""
28	
29	def __init__(self, ipv6_net=None, prefix=None):
30		""" Initialize IPv6 Address Range
31
32			Initialize `IPv6Net with IPv6 address and prefix.
33			If no IPv6 address is given, initialize to null address.
34			If no prefix is given, assume /128 (IPv6 address only).
35			:param ipv6_net: IPv6 Network Address.
36			:param prefix: IPv6 Network Adress Prefix.
37		"""
38		if ipv6_net is None:
39		    net = ipaddress.IPv6Network("::/0")
40		elif prefix is None:
41		    net = ipaddress.IPv6Network(ipv6_net)
42		else:
43		    tmp = ipv6_net + "/" + str(prefix)
44		    net = ipaddress.IPv6Network(tmp)
45
46		self.__ipv6_net = net.exploded
47	
48	def addr(self):
49		""" Returns address part only (no prefix) """
50		return ipaddress.IPv6Network(self.__ipv6_net).network_address.exploded
51	
52	def prefix(self):
53		""" Returns prefix only """
54		return ipaddress.IPv6Network(self.__ipv6_net).prefixlen
55	
56	def __str__(self):
57	    return ipaddress.IPv6Network(self.__ipv6_net).exploded
58	
59	def __repr__(self):
60	    return ipaddress.IPv6Network(self.__ipv6_net).exploded

OpenC2 IPv6 Address Range

IPv6 Address Range as defined in Sec. 3.4.1.9.

The Standard is not clear on this part. The IPv6Net Target is defined as "Array /ipv6-net" (where ipv6-net --lowercase!-- is never defined!) However, the json serialization requirements explicitely define: Array /ipv6-net: JSON string containing the text representation of an IPv6 address range as specified in [RFC4291], Section 2.3. According to this definition, I assume a single network address should be managed. Extension to an array of IP network addresses is rather straightforward by using a list for ipv6_net attribute. Note that I have to keep both the string representation of the network address as well as the IPv6Network object to easily manage the code and to automate the creation of the dictionary.

IPv6Net(ipv6_net=None, prefix=None)
29	def __init__(self, ipv6_net=None, prefix=None):
30		""" Initialize IPv6 Address Range
31
32			Initialize `IPv6Net with IPv6 address and prefix.
33			If no IPv6 address is given, initialize to null address.
34			If no prefix is given, assume /128 (IPv6 address only).
35			:param ipv6_net: IPv6 Network Address.
36			:param prefix: IPv6 Network Adress Prefix.
37		"""
38		if ipv6_net is None:
39		    net = ipaddress.IPv6Network("::/0")
40		elif prefix is None:
41		    net = ipaddress.IPv6Network(ipv6_net)
42		else:
43		    tmp = ipv6_net + "/" + str(prefix)
44		    net = ipaddress.IPv6Network(tmp)
45
46		self.__ipv6_net = net.exploded

Initialize IPv6 Address Range

Initialize `IPv6Net with IPv6 address and prefix. If no IPv6 address is given, initialize to null address. If no prefix is given, assume /128 (IPv6 address only).

Parameters
  • ipv6_net: IPv6 Network Address.
  • prefix: IPv6 Network Adress Prefix.
def addr(self):
48	def addr(self):
49		""" Returns address part only (no prefix) """
50		return ipaddress.IPv6Network(self.__ipv6_net).network_address.exploded

Returns address part only (no prefix)

def prefix(self):
52	def prefix(self):
53		""" Returns prefix only """
54		return ipaddress.IPv6Network(self.__ipv6_net).prefixlen

Returns prefix only