DHCP Encoding Class¶
- class bloxone.dhcp_encode[source]¶
Class to assist with Hex Encoding of DHCP Options and sub_options
- binary_to_hex(data)[source]¶
Format hex string of binary/hex encoded data
- Parameters
data (str) – data to format
- Returns
hex encoding as string
- boolean_to_hex(flag)[source]¶
Encode boolean value as single hex byte
- Parameters
flag (bool/str) – True or False as bool or text
- Returns
hex encoding as string
- empty_to_hex(data)[source]¶
Return empyt hex string ‘’
- Parameters
data (str) – Data not to encode (should be empty)
- Returns
Empty String ‘’
- encode_data(sub_opt, padding=False, pad_bytes=1)[source]¶
Encode the data section of a sub_option definition
- Parameters
sub_opt (dict) – Dict containing sub option details Must include ‘data’ and ‘type’ keys
padding (bool) – Whether extra ‘null’ termination bytes are req.
pad_bytes (int) – Number of null bytes to append
- Returns
Hex encoded data for specified data-type as string
- encode_dhcp_option(sub_opt_defs=[], padding=False, pad_bytes=1, encapsulate=False, id=None, prefix='')[source]¶
Encode list of DHCP Sub Options to Hex
- 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
- encode_sub_option(sub_opt, data_only=False, padding=False, pad_bytes=1)[source]¶
Encode individual sub option
- Parameters
sub_opt (dict) – Sub Option Definition, as dict.
data_only (bool) – Encode data portion only if True (Note the sub_opt dict is also checked for the ‘data-only’ key)
padding (bool) – Whether extra ‘null’ termination bytes are req.
pad_bytes (int) – Number of null bytes to append
- Returns
Encoded suboption as a hex string
- fqdn_to_hex(fqdn)[source]¶
Encode an fdqn in RFC 1035 Section 3.1 formatted hex
- Parameters
fqdn (str) – hostname to encode
- Returns
hex encoding as string
- 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
- int_to_hex(i, size=8)[source]¶
Encode integer of specified size as signed int in hex
- Parameters
i (int) – integer value to encode
size (int) – size in bits [8, 16, 32]
- Returns
hex encoding as string
- ip_to_hex(ip)[source]¶
Encode an IPv4 or IPv6 address to hex
- Parameters
ip (str) – IPv4 or IPv6 address as a string
- Returns
hex encoding as string
- ipv4_address_to_hex(ipv4)[source]¶
Encode an IPv4 address to hex
- Parameters
ipv4 (str) – IPv4 address as a string
- Returns
hex encoding as string
- ipv6_address_to_hex(ipv6)[source]¶
Encode an IPv6 address to hex
- Parameters
ipv6 (str) – IPv4 or IPv6 address as a string
- Returns
hex encoding as string
- optcode_to_hex(optcode)[source]¶
Encode Option Code in hex (1-octet)
- Parameters
optcode (str/int) – Option Code
- Returns
hex encoding as string
- string_to_hex(string)[source]¶
Encode a text string to hex
- Parameters
string (str) – text string
- Returns
hex encoding as string