How can I access the local subnet for an iOS device and ping an IP from there?

I've to perform several steps in loop.
For each IP in the local subnet:
  • Ping the IP. If not available (within a small/tuneable timeout eg. 200 ms), move on to next IP

  • If the IP pings back, send a POST authentication request.

  • Stop after an IP is authenticated succesfully.

  • Finally save the IP in the database for future use.

Now, I have no idea of how I can find the local subnet for an iOS device in the first place and secondly how can I ping an IP address(in Swift).


Replies

Is sounds like you need to reach out over the network and communicate / authenticate with that device without knowing the device's IP. This would be a perfect use case for Bonjour and Network Framework. For example, the device allowing authentication could also advertise a Bonjour service with NWListener and the browsing device could use NWBrowser to browse for that service and NWConnection to connect to the service and authenticate with the device.

Check out Building a Custom Peer-to-Peer Protocol for a sample on how to work with Network Framework and Bonjour.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com