Skip to content

Instantly share code, notes, and snippets.

@casebeer
Created January 7, 2014 23:28
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save casebeer/8308838 to your computer and use it in GitHub Desktop.
Save casebeer/8308838 to your computer and use it in GitHub Desktop.
Generate DHCP Option 121 hex routing configurations
'''
Generate DHCP Option 121 hex routing configurations
Static routes pushed over DHCP
1) Set option 121.
2) Value is the concatenation of hex route data.
3) Each route has the form:
{prefix_length}{destination_prefix}{router}
With all fields in hex, one octet for the prefix length,
ceil(prefix length / 8) octets for the destination prefix,
and four octets for the router address.
See also http://ercpe.de/blog/advanced-dhcp-options-pushing-static-routes-to-clients
'''
def hex_encode(route):
return b"".join([b"%02x" % octet for octet in route])
routes = [
(24, 10,1,10, 192,168,1,123 ),
(24, 10,1,11, 192,168,1,123 ),
(0, 192,168,1,1 ),
]
print(b"".join(hex_encode(route) for route in routes))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment