openc2lib.types.data.ipv4_addr
IPv4 Address
This module implements an IPv4 Address as described in Sec. 3.4.2.8.
The usage of the ipaddress module is compliant to what required in the language specification for IPv4 addresses, especially the following points: a) The IPv4 address should be available both in string and binary form b) The network representation is an array according to RFC 4632 Sec. 3.1 (host/prefix, host/mask, host/hostmask, etc.)
1""" IPv4 Address 2 3 This module implements an IPv4 Address as described in Sec. 3.4.2.8. 4 5The usage of the ipaddress module is compliant to what required in the 6language specification for IPv4 addresses, especially the following points: 7a) The IPv4 address should be available both in string and binary form 8b) The network representation is an array according to RFC 4632 Sec. 3.1 9 (host/prefix, host/mask, host/hostmask, etc.) 10""" 11 12import ipaddress 13 14class IPv4Addr: 15 """OpenC2 IPv4 Address" 16 17 This class implements an IPv4 Address as described in Sec. 3.4.2.8. 18 19 The usage of the ipaddress module is compliant to what required in the 20 language specification for IPv4 addresses, especially the following points: 21 a) The IPv4 address should be available both in string and binary form 22 b) The network representation is an array according to RFC 4632 Sec. 3.1 23 (host/prefix, host/mask, host/hostmask, etc.) 24 25""" 26 __ipv4_addr = ipaddress.IPv4Address("0.0.0.0") 27 """ Internal representation of the IPv4 address""" 28 29 def __init__(self, ipaddr=None): 30 """ Initialize IPv4 Address 31 32 An IPv4 address is built from a string that uses the common dotted notation. 33 If no IPv4 address is provided, the null address is used ("0.0.0.0"). 34 35 :param ipaddr: Quad-dotted representation of the IPv4 address. 36 """ 37 if ipaddr == None: 38 self.__ipv4_addr = ipaddress.IPv4Address("0.0.0.0") 39 else: 40 self.__ipv4_addr = ipaddress.IPv4Address(ipaddr) 41 42 def __str__(self): 43 return self.__ipv4_addr.exploded 44 45 def __repr__(self): 46 return self.__ipv4_addr.exploded
15class IPv4Addr: 16 """OpenC2 IPv4 Address" 17 18 This class implements an IPv4 Address as described in Sec. 3.4.2.8. 19 20 The usage of the ipaddress module is compliant to what required in the 21 language specification for IPv4 addresses, especially the following points: 22 a) The IPv4 address should be available both in string and binary form 23 b) The network representation is an array according to RFC 4632 Sec. 3.1 24 (host/prefix, host/mask, host/hostmask, etc.) 25 26""" 27 __ipv4_addr = ipaddress.IPv4Address("0.0.0.0") 28 """ Internal representation of the IPv4 address""" 29 30 def __init__(self, ipaddr=None): 31 """ Initialize IPv4 Address 32 33 An IPv4 address is built from a string that uses the common dotted notation. 34 If no IPv4 address is provided, the null address is used ("0.0.0.0"). 35 36 :param ipaddr: Quad-dotted representation of the IPv4 address. 37 """ 38 if ipaddr == None: 39 self.__ipv4_addr = ipaddress.IPv4Address("0.0.0.0") 40 else: 41 self.__ipv4_addr = ipaddress.IPv4Address(ipaddr) 42 43 def __str__(self): 44 return self.__ipv4_addr.exploded 45 46 def __repr__(self): 47 return self.__ipv4_addr.exploded
OpenC2 IPv4 Address"
This class implements an IPv4 Address as described in Sec. 3.4.2.8.
The usage of the ipaddress module is compliant to what required in the language specification for IPv4 addresses, especially the following points: a) The IPv4 address should be available both in string and binary form b) The network representation is an array according to RFC 4632 Sec. 3.1 (host/prefix, host/mask, host/hostmask, etc.)
30 def __init__(self, ipaddr=None): 31 """ Initialize IPv4 Address 32 33 An IPv4 address is built from a string that uses the common dotted notation. 34 If no IPv4 address is provided, the null address is used ("0.0.0.0"). 35 36 :param ipaddr: Quad-dotted representation of the IPv4 address. 37 """ 38 if ipaddr == None: 39 self.__ipv4_addr = ipaddress.IPv4Address("0.0.0.0") 40 else: 41 self.__ipv4_addr = ipaddress.IPv4Address(ipaddr)
Initialize IPv4 Address
An IPv4 address is built from a string that uses the common dotted notation. If no IPv4 address is provided, the null address is used ("0.0.0.0").
Parameters
- ipaddr: Quad-dotted representation of the IPv4 address.