|
|
Thread Tools | Search this Thread |
08-25-2012, 07:19 PM | #91 |
Connoisseur
Posts: 50
Karma: 10
Join Date: Feb 2011
Device: Android
|
Although whichever address calibre picks, it probably shouldn't ever pick loopback address 127.0.0.1 :-)
|
08-25-2012, 11:24 PM | #92 |
creator of calibre
Posts: 44,001
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
@chaley: One possibility is to create mdns records for every ip address. I dont know how well most mdns clients work with multiple entries for the same service, though. And of course some one will have to write code to get all ip addresses on all platforms.
|
08-26-2012, 03:42 AM | #93 | |
Grand Sorcerer
Posts: 11,776
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
The problem we are facing is that mdns seems to be disabled on *lots* of home networks. The percentage could be as high as 30%, but it is hard to know for sure. It is easier for people in that situation to enter a fixed address into CC than to figure out how to re-enable mdns in their router. This works in the majority of cases, but when someone both has non-enabled mdns and multiple networks, things can get dicey because of the need to choose between network adapters, or to even know that the choice must be made. Examples I have dealt with in the last day: - The one described in this thread just above, where the reason for multiple networks isn't known. - One where the user has a permanent outgoing VPN that tunnels through the router, creating two interfaces on the machine. - One where the user has virtual adapters to support VMs. - One where (apparently) the user had both cable and wifi enabled on the machine running calibre. |
|
08-26-2012, 04:55 AM | #94 |
creator of calibre
Posts: 44,001
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
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.
Another alternative is to get a list of interfaces and ask the user to choose, though this is less friendly. |
08-26-2012, 05:10 AM | #95 | ||
Grand Sorcerer
Posts: 11,776
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
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. |
||
08-26-2012, 05:28 AM | #96 |
creator of calibre
Posts: 44,001
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
A slightly offbeat idea. Have CC use mdns to advertise itself (if android allows that). Then if calibre detects CC, choose the best IP as the IP on the same subnet as CC.
Though I suppose this will not work on networks where mdns is disabled anyway. Last edited by kovidgoyal; 08-26-2012 at 05:44 AM. |
08-26-2012, 05:30 AM | #97 |
creator of calibre
Posts: 44,001
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Another interesting module that might help is netifaces:
http://alastairs-place.net/projects/netifaces/ |
08-26-2012, 05:35 AM | #98 |
creator of calibre
Posts: 44,001
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Never mind.
|
08-26-2012, 05:51 AM | #99 |
creator of calibre
Posts: 44,001
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Just as a datapoint, on my machine:
socket.gethostbyname_ex('127.0.0.1') returns ('127.0.0.1', [], ['127.0.0.1']) whereas pprint.pprint([netifaces.ifaddresses(x).get(netifaces.AF_INET, None) for x in netifaces.interfaces()]) [[{'addr': '127.0.0.1', 'netmask': '255.0.0.0', 'peer': '127.0.0.1'}], [{'addr': '192.168.1.2', 'broadcast': '192.168.1.255', 'netmask': '255.255.255.0'}], None, [{'addr': '172.16.217.1', 'broadcast': '172.16.217.255', 'netmask': '255.255.255.0'}], [{'addr': '192.168.81.1', 'broadcast': '192.168.81.255', 'netmask': '255.255.255.0'}]] Which seems a lot more useful. |
08-26-2012, 09:32 AM | #100 |
Grand Sorcerer
Posts: 11,776
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
@kovid: I had made the gethost... stuff work on my windows machine, but I failed completely to make it work on linux. So I agree with you, it is not useful.
However, netifaces does seem to do the trick. On my windows machine the same "program" returns Code:
[[{'addr': '169.254.108.184'}], [{'addr': '192.168.220.38', 'broadcast': '192.168.220.255', 'netmask': '255.255.255.0'}], [{'addr': '127.0.0.1', 'broadcast': '127.255.255.255', 'netmask': '255.0.0.0'}], None, None, None] We could also do a variant of what you suggested earlier. Instead of using mdns, which seems to have its own set of problems, we could have a "reverse connect" test. The user would push some button on the device that would cause the device to listen on a port on the wifi, displaying the IP address and port. The user would then push some button in calibre that asks for the device's address and port (supplied in the above dialog) and connects to it. If this connect succeeds, we can easily get calibre's local address from the socket, or even better have the device get the remote address from its socket. In addition to verifying connectivity, this test would supply some diagnostic information we can use to help. It is more complicated to build than using netifaces to display info, but not outrageously so. So, are you willing to package netifaces into calibre? If you are, then could you produce a "beta" so I can code and test in preparation for next Friday? The beta could be windows only. Thanks. Last edited by chaley; 08-26-2012 at 09:35 AM. |
08-26-2012, 12:01 PM | #101 |
Wizard
Posts: 1,343
Karma: 2786741
Join Date: May 2012
Location: Birmingham, AL
Device: Sony Reader PRS-T1, Kindle Touch, misc. Android devices, Nook HD+
|
My old 2Wire home gateway defaulted to 172.16.0.1/16 and issued 172.16.1.* addresses via DHCP. The current 2Wire used by AT&T U-Verse defaults to 192.168, though.
|
08-26-2012, 12:12 PM | #102 | |
Grand Sorcerer
Posts: 11,776
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
At least that is one of the private ranges. If we find several IP addresses with only one in a private range, we can probably safely propose that one. Unfortunately that also won't be ironclad rule. Kovid's output above shows that he is using 3 private addresses, 2 class C and 1 class B. |
|
08-26-2012, 12:24 PM | #103 |
creator of calibre
Posts: 44,001
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
I'm willing to bundle it, for your testing you dont need a beta. Just stick the netifaces install into some directory and add it to sys.path before importing netifaces in calibre.
|
08-26-2012, 12:34 PM | #104 |
Well trained by Cats
Posts: 29,958
Karma: 55705602
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Can you grab the 'Gateway' address and use that as a best guess (subnet)?
Last edited by theducks; 08-26-2012 at 12:35 PM. Reason: clairify |
08-26-2012, 12:37 PM | #105 |
Grand Sorcerer
Posts: 11,776
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
This isn't reliable. At least one of the cases I worked on last night, and possible a second, had a VPN running. In this case the gateway will be set to the VPN's virtual interface, not the physical interface it is tunneling over.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Android App] Calibre Companion 1.7 Beta testing | Adoby | Devices | 31 | 09-07-2012 10:13 PM |
[Android App] Coming: Android app to connect as a device to calibre using wifi | chaley | Devices | 92 | 09-07-2012 08:24 PM |
[Android App] Can't get Calibre Companion to connect | theangelicious1 | Devices | 2 | 09-01-2012 04:09 AM |
calibre - send to device - android running Nook App. | Mad_Robot | Devices | 6 | 10-16-2011 01:49 PM |
Android app for reading web articles with Kindle (app and device) | fivefilters | Android Devices | 0 | 07-02-2011 09:29 PM |