title: Need more ideas: How to check if iPhone is in Wifi
body: <p>i have a Debian server. This server should check if iPhones available in my home wifi.
  The problem is, that i-Devices suspend the wifi module to safe power if mobile data is available. So one solution is, just turn off mobile data and discovery in wifi works fine. (But this is not a real solution for me, because it is annoying to do this manually every time you are at home and other people will use this software, too.) </p>
  
  <p>Tested so far with a iPad Mini and a iPhone5 (ios7):</p>
  
  <ol>
  <li><p>I have done the task for android, in Android there is a broadcast if my network connectivity change, so i just have to catch the broadcast programmatically and register me on my Debianbox.
  Tried the same on the iDevice but it seems not possible to intercept Wifi-Status-Changes in Objective-C in Background. In foreground its possible through the Apple-Reachability-Class.
  But I need it in Background, so this is not possible for me.</p></li>
  <li><p>Scan all Ports of my iPhone and try to do requests with the hope that this wake up my Wifi-Module:</p>
  
  <ul>
  <li><p>Open UDP Ports:</p>
  
  <ul>
  <li>PORT      STATE         SERVICE       VERSION</li>
  <li>999/udp   open|filtered applix</li>
  <li>1090/udp  open|filtered ff-fms</li>
  <li>5001/udp  open|filtered commplex-link</li>
  <li>5353/udp  open|filtered zeroconf</li>
  <li>18134/udp open|filtered unknown</li>
  <li>19141/udp open|filtered unknown</li>
  <li>19717/udp open|filtered unknown</li>
  <li>20919/udp open|filtered unknown</li>
  <li>21354/udp open|filtered unknown</li>
  <li>31625/udp open|filtered unknown</li>
  <li>49191/udp open|filtered unknown</li>
  <li>57409/udp open|filtered unknown</li>
  </ul></li>
  <li><p>Open TCP Ports:</p>
  
  <ul>
  <li>PORT      STATE SERVICE    VERSION</li>
  <li>62078/tcp open  tcpwrapped</li>
  </ul></li>
  </ul>
  
  <p>I tried to make requests with <em>netcat</em> on Port 5353 UDP (Bonjour/MDNS). The result is that the iDevices really wakes the wifi module in the first 30 Minutes! After that period of time its kind of luck if the request wake up the wifi module. I think there is maybe a "deep sleep" after about 30 minutes.</p></li>
  <li><p>MacBookPro as wifi hotspot and iDevices connected to this. Then I sniffed the whole traffic with Wireshark to check what messages are send via Wifi. At least found a MDNS multicast which is done by every iOS7 Device. This messages can be catch by a little python server.
  -> Works, but the period the devices sending multicasts is 1 minute up to 30+ minutes, so its not solid.</p></li>
  <li><p>A creative way: Silent Push Notification to wake up the iDevice, after that ping in wifi is possible. So the push notification just wake up my wifi!
  -> Works, but the APN Server don't tell you if the push-message was delivered, so its not very solid. I have tested this and some times the APN Server "swallow" the message. And every 5 minutes a internet-connectivity and mobile data traffic to check if my device is in wifi...thats not really best practice. But best solution so far for battery-life.</p></li>
  <li><p>Trigger that you are at home with a geofence region. This is possible, and works but it cost so much battery. But maybe there is no other good solution.</p></li>
  <li><p>arp-scan is a tool that makes arp-request to a ip-range. This don't work if mobile data is turned on, otherwise it does.</p></li>
  </ol>
  
  <p>So my questions:</p>
  
  <ul>
  <li>Is there a request on a specific port that i can send to wake up wifi-module of the iDevice?</li>
  <li>Is there maybe a objective-c way to solve this task?</li>
  <li>Can I send a MDNS request and the iDevice will answer it?</li>
  <li>Can I create a App that has a background-listening socket and the Debianbox connect to that?</li>
  <li>Any other Ideas that can solve this task? I'm out of ideas.</li>
  </ul>
  
  <p>Thanks  </p>