How to detect a mobile device when it connects to a home wifi network?

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!


Solution 1:

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.

Sometimes I needed the -r 3 flag, which runs it three times; works much better as the default 2 times, which sometimes miss some devices. Thus:

 sudo arp-scan -l -r 3 | grep {Phone Static Assigned IP} 

works better for me to LG V30+.

Solution 2:

import subprocess

if __name__ == '__main__':
    while True:
        sleep(5)
        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!"
        else:
            print "The device is not present!"

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