View Single Post
Old 08-26-2012, 05:10 AM   #95
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,476
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by kovidgoyal View Post
Ah well, then you are down to doing lots of networking magic. At least on linux, what I would do is examine the routing table, find the default gateway and then pick the interface address that falls in the same subnet as the gateway. That should take care of 90% of these cases. While I (more or less) know how to do that on linux, I have no idea on the other platforms.
Neither do I. Also, this algorithm would have picked the wrong interface in the VPN case, because the default gateway is the VPN. I suppose we could notice that the interface is a TAP or TUN (or some other virtual interface) and chase the chain until we get to a real one, but there is no guarantee that the interface we arrive at is actually the LAN.
Quote:
Another alternative is to get a list of interfaces and ask the user to choose, though this is less friendly.
One thought I had is to scan the interfaces, get the IP addresses, and propose any 192.168. one. My guess is that if someone is using another private range then the person can cope with finding the right address. I know of no home router that does not use the 192.168 range, but of course that doesn't mean that there isn't one.

The next thing I intend to do is see if I can get the list of IP addresses using the standard python API. gethostbyname_ex('127.0.0.1') seems to do what I want, but I need to play with it to see. That is on my queue for today, after I finish exploring how stupidly SQLite uses indices.
chaley is offline   Reply With Quote