''' 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))