Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

What would be the best way to have a server recognize when a specific mobile device (cell phone, iPad, etc.) connects to the network (wirelessly, of course)?

As an example situation, a person has his home wifi network properly configured on his cellphone. When he gets within range of the router, it would connect (nothing new about that). Upon connection to that router, his home server would launch a certain program (or throw a notification, write to a file, etc.).

I thought that a possible solution would be a network-hosted custom "web app" that would be launched from the phone so that the server would recognize the page was called. However, if this could be done when the phone connects automatically, that would be best.

Any thoughts or alternate solutions would be greatly appreciated, so thanks in advance!

share|improve this question
    
If it is an android phone a cron job wgetting a local website would be easiest. To do it from the network side you would have to use RADIUS protocol and have a properly setup RADIUS server. –  Huckle May 27 '12 at 23:18
add comment

5 Answers 5

if __name__ == '__main__':
 while True:
  sleep(5)
  p = subprocess.Popen("arp-scan -l | grep xx:xx:xx:xx:xx:xx", stdout=subprocess.PIPE, $
  (output, err) = p.communicate()
  p_status = p.wait()
  if output:
    print "Yay, the devine is connected to your network!"
  else:
    print "The device is not present!"

This way you can scan for the MAC of your device :)

share|improve this answer
add comment

I wrote a script that does something similar using arp-scan and a static IP address on an iPhone.

You can find the code here: https://github.com/blackairplane/pydetect

It needs to be cleaned up as I am new to Python, but I think it illustrates the concept.

share|improve this answer
add comment

I think this can be easily accomplished by arp-scan.

Install arp-scan: sudo apt-get install arp-scan
Detect all the hosts on the local network: sudo arp-scan -l

You can set up a crontab to periodically (every 2 mins maybe) run a script that scans the network with arp-scan and parses its output to discover the active hosts.

share|improve this answer
    
It should be noted that some devices might not show up unless they are turned on. My nexus 4 won't show up unless the screen is on. –  Nicolas Bouliane May 19 at 2:00
add comment

I am actually contemplating to implement a solution for this that meets following requirements:

  1. The phone does not need to have assigned IP address on the network.
  2. The phone does not need to periodically send out signals that would drain its battery.
  3. If there are many phones on the network, all of them would be detected.

My intention is to mount the phones filesystem with ssh, but it could be used for whatever.

Let's say the local network is 192.168.1.0...

So I would implement an APP that listens to UDP broadcasts from the broadcast address: 192.168.1.255. This app would not drain battery as it totally passive. (it only gets active when a packet is received).

A daemon on the computer will will periodically send out broadcasts to the broadcast address 192.168.1.255. The phone will reply to such signals giving its name, id, ip address etc.

Now the computer know that the phone exists on the network and for my case can invoke sshfs mount.

Surely this needs a lot of work, including programming work, and is not easy. But I think it would be the most reliable and reasonable solution.

share|improve this answer
add comment

The best way I can think of is to give said device a static IP address, and use a simply script to ping the device every X seconds and trigger your program / notification.

Things to note: Many phones won't connect to the wifi network until the wake up from sleep. Your script will need to be able to tell the difference between the phone going to sleep and the phone leaving the house, possibly by considering the time of day. After that, having the script trigger a program to run or a notification to appear is trivial.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.