mariusmotea / diyHue

Philips Hue emulator that is able to control multiple types of lights
Other
627 stars 107 forks source link

Wrong gateway selection on non Class C networks #403

Closed adyanth closed 5 years ago

adyanth commented 5 years ago

In the code, there is a section to find gateway as bridge_config["config"]["gateway"] = ip_pices[0] + "." + ip_pices[1] + "." + ip_pices[2] + ".1"

Which essentially assumes the gateway IP as *.1. But the problem arises when the network is not a class C. I have which is a Class A network with device IP 10.3.14.15 and gateway 10.0.0.1 which makes it impossible to add lights after discovered by the Hue app. IMHO it is better to find the gateway by looking at the default routes rather than assuming a limited /24 network.

ghost commented 5 years ago

@adyanth Any suggestions for a fix? @mariusmotea Any ideas for a fix also? A quick google turned up this!

mariusmotea commented 5 years ago

i gave a better idea on how to get the default gateway. I will add this to futures list.

dfloer commented 5 years ago

I think we need more robust networking here, I think we may need to pull in another dependency like I did for the discovery code I wrote in my fork and referenced in #294 .

juanesf commented 5 years ago

Will serve?

ip a s|sed -ne '/127.0.0.1/!{s/^[ \t]inet[ \t]([0-9.]+)\/.*$/\1/p}'

adyanth commented 5 years ago

@adyanth Any suggestions for a fix? @mariusmotea Any ideas for a fix also? A quick google turned up this!

This StackOverflow solution with python should work well if the second check for the flag to indicate that the route is for a gateway is replaced with check for usable route, since on my bash on windows does not list the default route with a gateway flag, and it might happen on the raspberry pi too. Anyways, as long as it is a default route and flag indicates it is usable, it should not be a problem.

Or for cross-compatibility with other OSes the next answer using netifaces would be good.

ghost commented 5 years ago

Closing this issue but adding it to the project board for future development. Please feel free to continue discussing solutions here or on slack