I have a perl script to calculate routes to hexadecimal, so it works with MikroTik DHCP Server. I’m now asking if anyone has anything similar, Linux binary or source code etc.?
The Classless Static Route Option for Dynamic Host Configuration Protocol (DHCP) version 4.
No Linux binaries nor C/C++ code here. How about a quick Ruby translation using the excellent ‘ipaddress’ gem?
(See: https://github.com/bluemonk/ipaddress for ‘ipaddress’ gem info…)
I ripped this from some DHCP Ruby code I’ve been using (a Ruby library that parses and generates DHCP packets) and added the hexification like your script.
Oh, this script makes an assumption that the GATEWAY IP address will always be ON or PART of the network. Therefore each argument is a gateway IP/mask where the mask can either be a four-octet version (i.e. “255.255.255.0”) or a CIDR integer number of mask bits (0 through 32 inclusive).
So if the network is 192.168.100.0/24 and the gateway is at .1, I would do:
Unlike the prior posted Perl script, this won’t handle a gateway IP that doesn’t fall within the network without some adaptation. (Does that ever happen? Would it ever work?)