DHCP Decoding Class¶
-
class
bloxone.
dhcp_decode
[source]¶ Class to assist with Hex Encoding of DHCP Options and sub_options
-
check_data_type
(optcode, sub_defs=[])[source]¶ Get data_type for optcode from sub optino definitions
Parameters: - optcode (int) – Option code to check
- sub_defs (list of dict) – sub option definitions to cross reference
Returns: data_type as str
-
decode_dhcp_option
(hex_string, sub_opt_defs=[], padding=False, pad_bytes=1, encapsulated=False, id=None, prefix='')[source]¶ Attempt to decode DHCP options from hex representation
Parameters: - sub_opt_defs (list) – List of Sub Option definition dictionaries
- padding (bool) – Whether extra ‘null’ termination bytes are req.
- pad_bytes (int) – Number of null bytes to append
- encapsulate (bool) – Add id and total length as prefix
- id (int) – option code to prepend
- prefix (str) – String value to prepend to encoded options
Returns: Encoded suboption as a hex string
-
get_name
(optcode, sub_defs=[])[source]¶ Get data_type for optcode from sub optino definitions
Parameters: - optcode (int) – Option code to check
- sub_defs (list of dict) – sub option definitions to cross reference
Returns: name as str
-
hex_length
(hex_string)[source]¶ Encode Option Length in hex (1-octet)
Parameters: hex_string (str) – Octet Encoded Hex String Returns: Number of Hex Octects as hex encoded string
-
hex_string_to_list
(hex_string)[source]¶ Take a hex string and convert in to a list
Parameters: hex_string (str) – Hex represented as string Returns: list of hex bytes
-
hex_to_array_of_ip
(hex_string)[source]¶ Decode array of IPv4 or IPv6 addresses to CSV string
Parameters: hex_string (str) – Hex representation of an array of IPv4 or IPv6 Returns: IP Addresses in a CSV string
-
hex_to_binary
(data)[source]¶ Format hex string of binary/hex encoded data
Parameters: data (str) – data to format Returns: hex encoding as string
-
hex_to_boolean
(hex_string)[source]¶ Decode Hex value as a string to ‘true’ or ‘false’
Parameters: hex_string (str) – Hex value as a str Returns: string representation of a boolean
-
hex_to_empty
(data)[source]¶ Return empyt hex string ‘’
Parameters: data (str) – Data not to encode (should be empty) Returns: Empty String ‘’
-
hex_to_fqdn
(hex_string)[source]¶ Decode RFC 1035 Section 3.1 formatted hexa to fqdn
Parameters: hex_string (str) – hex encoded fqdn Returns: fqdn as string
-
hex_to_int
(hex_string, size=8)[source]¶ Decode hex to signed integer of defined size
Parameters: - hex_string (str) – hex value as string
- size (int) – size in bits [8, 16, 32]
Returns: integer
-
hex_to_ip
(hex_string)[source]¶ Decode a 4 or 16 octect hex string to an IPv4 or IPv6 string
Parameters: hex_string (str) – Hex representation of an IPv4 or IPv6 address Returns: IP Address as a string
-
hex_to_ipv4_address
(hex_string)[source]¶ Decode a hex string to an IPv4 Address as a string
Parameters: hex_string (str) – Hex representation of an IPv4 address Returns: IPv4 Address as a string
-
hex_to_ipv6_address
(hex_string)[source]¶ Decode a hex string to an IPv6 address as a string
Parameters: hex_string (str) – Hex representation of an IPv6 address Returns: IPv6 Address as a string
-
hex_to_optcode
(hex_string)[source]¶ Encode Option Code in hex (1-octet)
Parameters: optcode (str/int) – Option Code Returns: hex encoding as string
-
hex_to_string
(hex_string)[source]¶ Decode a string of hex values to a text string
Parameters: hex_string (str) – Hex representation of a string Returns: text string (str)
-
hex_to_suboptions
(hex_string, encapsulated=False)[source]¶ Extract the sub-options from the hex data
-
hex_to_uint
(hex_string, size=8)[source]¶ Encode integer of specified size as unsigned int in hex Uses 2’s compliment if supplied with negative number
Parameters: - i (int) – integer value to encode
- size (int) – size in bits [8, 16, 32]
Returns: hex encoding as string
-