List of IP addresses of all devices on a Wi-Fi network of iOS sdk without bonjour?

I am trying to get a list of all the IP addresses on the local network. The reason for this is because I am writing an application using the STAR TSP100LAN printer.

The process of obtaining the printer's IP address is rather cumbersome for the end user. This includes turning off the printer, holding the paper feed button, turning the printer on again, waiting 15 seconds for the printer to obtain an IP address through DHCP, and then finally spitting out a receipt with this information on it.

Having seen that the printer is not turned on by Bonjour, is it possible to obtain an IP address using other methods?

Any help is much appreciated! I hope this is not a repeated question, but through my searches I cannot find a solution!

UPDATE : After a little thought, I came up with a pseudo-solution:

  • Find the current iPad address of the iPad through NSHost.

  • Remove the last quadrant from IPAddress

  • Using the stripped row as a prefix, repeat 1-255 for the last quadrant

  • Each iteration tries to open the port to the specified address using the sdk printer. If I get a valid answer, I know that IP is a printer. If not, I exclude IP from the list of available printers.

While this works, I set a timeout of 5 milliseconds for each attempt to open the port. But they found that this could return some null results, even though there actually is a printer on the network with an assigned IP address.

Perhaps if I get a null result, the first time I should increase the timeout to 15 milliseconds for the second search attempt.

+8
ios objective-c
source share
2 answers

Your approach to polling a local / 8 subnet is probably the best you can do. I can not find any API to get more detailed information about the network interface (e.g. subnet mask) in iOS. (Although using a subnet mask would be a better way to determine the range to repeat if you could get one.)

As you saw, 5ms is a rather complicated interval; In my experience, 15 ms can be pretty tough for a TCP connection over Wi-Fi. As a next step, I propose to parallelize the range survey and thereby allow you to extend the interval that you are ready to wait. The simplest way is probably to use a GCD. You can also start this polling process in the background before the user clearly needs a printer, which can improve the user's sensitivity to the perception of your application.

Alternatively, you can use the CFSocket API to open all of these connections (CFSocketCreate, CFSocketConnectToAddress and friends) and get parallelism by serving them all in the main thread using callbacks / runloop. Then, when these callbacks come in, pay attention to which addresses respond to this port. If for some reason the printer does not use TCP, this should be workable. Once you know which addresses respond to this port in general, you can iterate over this (hopefully much smaller) list that connects to the printer SDK itself. This approach will give you even more (and more elegant) parallelism than spawning a huge number of GCD streams, but it can be hard to get around if you haven't worked with runloops before.

Hope this helps.

+2
source share

You can quickly bring the list down from 255 to a smaller number by checking the broadcast address and then looking at the arp cache.

Only works for hosts that respond to broadcast messages.

0
source share

All Articles