lakinduakash / linux-wifi-hotspot

Feature-rich wifi hotspot creator for Linux which provides both GUI and command-line interface. It is also able to create a hotspot using the same wifi card which is connected to an AP already ( Similar to Windows 10).
BSD 2-Clause "Simplified" License
3.04k stars 282 forks source link

DHCP Range Configuration #347

Closed DevinKott closed 5 months ago

DevinKott commented 10 months ago

This PR is linked to issue #336 .

I needed the ability to set a custom DHCP range for my use-cases. For example, I wanted the following IPs to be assigned to connections:

192.168.1.150 -> 192.168.1.160

In the current linux-wifi-hotspot version, this is not possible. Here is how the dhcp-range configuration value is set (link here) currently:

dhcp-range=${GATEWAY%.*}.1,${GATEWAY%.*}.254,255.255.255.0,24h

As you can see, the range is hardcoded to be [1, 254].

I have updated this piece of code to include configurable ending ranges (see code changes below).

By default, the range is still set to [1, 254]. However, if the dhcp-range option is passed on the command line or a configuration value of DHCP_RANGE is changed then those values are taken instead.

Examples:

--dhcp-range 150,160
--dhcp-range 155,165

Values are validated against the range [1, 254] (inclusive) and the condition lower < upper. Aside from those restrictions, I feel that any ranges specified by the user would be at the fault of the user themselves.

If any errors occur (non-integer types, range check fails, etc.) then the default [1, 254] range is used.

Aside from the feature changes, I have also updated the READMEs to include the feature description and an example, and the version flag has been updated.

Please let me know if there is anything else I need to do/change and I would be happy to respond.

lakinduakash commented 10 months ago

Thanks for the contribution. I'll review this ❤️