Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Devices

Notices

Reply
 
Thread Tools Search this Thread
Old 08-25-2012, 07:19 PM   #91
ellett
Connoisseur
ellett began at the beginning.
 
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 :-)
ellett is offline   Reply With Quote
Old 08-25-2012, 11:24 PM   #92
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,776
Karma: 22666666
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.
kovidgoyal is offline   Reply With Quote
Old 08-26-2012, 03:42 AM   #93
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: 11,703
Karma: 6658935
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by kovidgoyal View Post
@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.
Kovid, as far as I can tell, calibre's mdns advertizes on every network and responds to a query on any given network with the right address for that network. This is rather easy to see if you enable wifi on a machine that is also cabled. You see two entries in mdns, one for each interface on the advertiser. You also see a confused user.

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.
chaley is offline   Reply With Quote
Old 08-26-2012, 04:55 AM   #94
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,776
Karma: 22666666
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.
kovidgoyal is offline   Reply With Quote
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: 11,703
Karma: 6658935
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
Old 08-26-2012, 05:28 AM   #96
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,776
Karma: 22666666
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.
kovidgoyal is offline   Reply With Quote
Old 08-26-2012, 05:30 AM   #97
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,776
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Another interesting module that might help is netifaces:
http://alastairs-place.net/projects/netifaces/
kovidgoyal is offline   Reply With Quote
Old 08-26-2012, 05:35 AM   #98
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,776
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Never mind.
kovidgoyal is offline   Reply With Quote
Old 08-26-2012, 05:51 AM   #99
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,776
Karma: 22666666
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.
kovidgoyal is offline   Reply With Quote
Old 08-26-2012, 09:32 AM   #100
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: 11,703
Karma: 6658935
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]
which is indeed useful. If nothing else I can get the list of possible IP addresses. Coupled with having the device show its own IP address (which we can do easily), the user should be able to compare the lists to identify the right one for calibre.

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.
chaley is offline   Reply With Quote
Old 08-26-2012, 12:01 PM   #101
hwlester
Wizard
hwlester ought to be getting tired of karma fortunes by now.hwlester ought to be getting tired of karma fortunes by now.hwlester ought to be getting tired of karma fortunes by now.hwlester ought to be getting tired of karma fortunes by now.hwlester ought to be getting tired of karma fortunes by now.hwlester ought to be getting tired of karma fortunes by now.hwlester ought to be getting tired of karma fortunes by now.hwlester ought to be getting tired of karma fortunes by now.hwlester ought to be getting tired of karma fortunes by now.hwlester ought to be getting tired of karma fortunes by now.hwlester ought to be getting tired of karma fortunes by now.
 
hwlester's Avatar
 
Posts: 1,343
Karma: 2786741
Join Date: May 2012
Location: Birmingham, AL
Device: Sony Reader PRS-T1, Kindle Touch, misc. Android devices, Nook HD+
Quote:
Originally Posted by chaley View Post
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.
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.
hwlester is offline   Reply With Quote
Old 08-26-2012, 12:12 PM   #102
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: 11,703
Karma: 6658935
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by hwlester View Post
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.
Well, there was really no chance that such a sweeping statement could be right.

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.
chaley is offline   Reply With Quote
Old 08-26-2012, 12:24 PM   #103
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,776
Karma: 22666666
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.
kovidgoyal is offline   Reply With Quote
Old 08-26-2012, 12:34 PM   #104
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,689
Karma: 54369090
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
theducks is online now   Reply With Quote
Old 08-26-2012, 12:37 PM   #105
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: 11,703
Karma: 6658935
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by theducks View Post
Can you grab the 'Gateway' address and use that as a best guess?
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.
chaley is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

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


All times are GMT -4. The time now is 09:47 PM.


MobileRead.com is a privately owned, operated and funded community.