Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
Why not just review your router logs. Since these logs are text based it would be easy to query the logs and get only the information you need. Surely someone has written the code to do this but if not it would be a simple exercise. – Horace Feb 3 at 22:51

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 '14 at 2:00
import subprocess

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

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

share|improve this answer

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

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

So I would implement an APP that listens to UDP broadcasts from the broadcast address: 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 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

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:

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

share|improve this answer

Your Answer


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.