-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdraytek_dhcp_options.py
63 lines (42 loc) · 2.48 KB
/
draytek_dhcp_options.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Description: This script is used to convert domain suffixes to hexadecimal for use in DHCP option 43
# Author: James Sawyer
# Email: [email protected]
# Website: http://www.jamessawyer.co.uk/
"""
The domain suffixes presented in hexadecimal with a number indicate the length in front of it. For example, "draytek.com"
should be presented as "076472617974656b03636f6d" where 07 means there are 7 characters followed, 6472617974656b is "draytek",
03 means there are 3 characters followed, and 636f6d is "com"""
""" This tool is specifically designed for DreyTek routers. It allows users to easily configure and manage their DreyTek routers,
including setting up network security, parental controls, and other advanced features.
Disclaimer: This tool is not affiliated with or endorsed by DreyTek. Use of this tool is at your own risk.
We are not responsible for any damage or data loss that may result from using this tool.
Please make sure to backup your router settings before using this tool. """
# https://www.draytek.com/support/knowledge-base/5314
def domain_to_hex(domain):
# Split the domain into its individual segments
segments = domain.split(".")
# Initialize a list to store the hexadecimal representation of each segment
hex_segments = []
# Loop through each segment of the domain
for segment in segments:
# Convert the segment to its hexadecimal representation
hex_segment = segment.encode("utf-8").hex()
# Add the length of the segment (in hexadecimal) to the beginning of
# the hexadecimal representation
hex_segment = "{:02x}".format(len(segment)) + hex_segment
# Add the segment to the list of hexadecimal segments
hex_segments.append(hex_segment)
# Join the hexadecimal segments together with a "." to create the final
# hexadecimal representation of the domain
hex_domain = "".join(hex_segments)
return hex_domain
def create_dhcp_43(domain_suffixes):
# Convert the domain suffixes to their hexadecimal representation
hex_suffixes = domain_to_hex(domain_suffixes)
# Create the 6-byte DHCP option 43 by concatenating the hexadecimal representation of the domain suffixes
# with the necessary padding to make the total length 6 bytes
dhcp_43 = hex_suffixes + "00" * (6 - (len(hex_suffixes) // 2))
return dhcp_43
# Test the function with the domain "local.lan"
print(domain_to_hex("local.lan")) # should output "056c6f63616c036c616e"
print(domain_to_hex("192.168.1.250"))