Created
January 7, 2014 23:28
-
-
Save casebeer/8308838 to your computer and use it in GitHub Desktop.
Generate DHCP Option 121 hex routing configurations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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