Detect when device joins wireless network (airport router)

0

I'm reposting this question with a more clear description as the other one was closed. Not sure if there's a different way to do this or not.

Is there any way to detect when a device joins my network via the (mac) terminal. I want to trigger certain actions when I get home and was hoping to use when my phone connects to wifi as the trigger.

I realize it'll connect/disconnect while I'm at home so I was going to play around with filtering those out in software, but for now is there any way to sniff what devices are on.

I don't mind just looking for MAC addresses. Would rather not have to jailbreak the phone for the solution.

I have a time capsule (essentially an airport extreme) as my router.

Tal

Posted 2013-03-05T21:53:22.407

Reputation: 101

If you have a computer always on it can detect the presence of another device scanning the network and testing for a MAC address. I have a PHP shell script that does exactly this. I use it in revers to scan when a device is not present to detect if the connection is down. Do you have a Mac or Linux computer on and available? – FrancescoMM – 2017-12-06T11:09:22.353

Answers

0

I use a PHP "shell" script similar to this, launched from terminal to test if one or more devices are down/disconnected. I use it to monitor if a Wifi bridge has gone down (if it can't see MAC address of devices on the other side of the bridge, then assume it's gone down):

#!/usr/bin/php
<?php
    $MULTICAST_ADDR='192.168.99.255';
    $DEVICES_TO_TEST_FOR_BRIDGE=array( // list of MACs
        'XX:XX:63:f2:XX:XX',
        'XX:XX:d0:ad:XX:XX',
        'XX:XX:b9:eb:XX:XX'
    );
    $SLEEP=10000000; // one sec = 1000000, sleep before reconnect


    while(TRUE) {
        usleep($SLEEP);

        flush();

        `ping -b -c 3 -t 3 $MULTICAST_ADDR 2> /dev/null`;

        flush();

        $res=`arp -an`;

        $bridgeIsOn=FALSE;
        echo("DEVICES:\n");
        echo($res);
        echo("\n");

        foreach($DEVICES_TO_TEST_FOR_BRIDGE as $deviceToTestForBridge) {
            if (strpos($res, $deviceToTestForBridge) !== false) {
                $bridgeIsOn=TRUE;
                $lastBridgeOn=time();
            }
        }

    if(!$bridgeIsOn && (time()-$lastBridgeOn>5*60) ) { // If bridge is down for 5 minutes
        echo("    BRIDGE HAS BEEN OFF FOR LONG (".(time()-$lastBridgeOn)."s) - REQUESTING A RESTART\n");

        // Do something here
    }
}

What it does is like, in a terminal, typing

    ping -b -c 3 -t 3 192.168.99.255 2> /dev/null

My devices are in the range 192.168.99.xxx, .255 means "them all". So ping them all and ignore the replies.

And then reading the arp tables with command

    arp -an

The rest of the code is to compare the list with the devices I want. At the end of the loop, $bridgeIsOn is either TRUE or FALSE, and $lastBridgeOn has the time it last was seen on, so I can make choices and execute stuff. In your case you must revert the logic, $bridgeIsOn means your phone is on the network: if($bridgeIsOn) { /* do something */}

I save the script as "monitorbridge", make it executable and launch it in a terminal

    ./monitorbridge

The script stays on until I close the terminal or type ^C. You can of course have it start at login or boot.

FrancescoMM

Posted 2013-03-05T21:53:22.407

Reputation: 51

This runs on a linux mini PC but it should run mostly the same on any machine that has PHP installed and accepts the ping and arp commands. on windows to launch it you would call it with php monitorbridge instead of just ./monitorbridge but essentially it should work the same. On Macs it shoud work fine provided PHP is enabled. The syntax of the ping and arp commands may be adjusted – FrancescoMM – 2017-12-06T11:37:45.110

0

Doing this is likely to be extremely hard, if its possible at all. It may make more sense to look at some kind of "work around", depending on your hardware, requirements and skillset.

One thought would be to ensure that your phones WIFI connection is always assigned a specific IP address (either static addressing or getting the Wifi router to dynamically assign a static IP) and then run a periodic script (Cronjob on your MAC ?) which pings your cellphone and looks for a response [or the addition of its MAC address to your arp cache if it does not respond ]. This is probably the easiest solution.

Speculating [ I do not own Apple Products and have never played with Radius Authentication for WIFI devices ], an alternative may be to upgrade/reconfigure your router to do Radius Authentication for your WIFI connection, run the Radius server on your Mac and have it trigger the script you want to run when it connects.

davidgo

Posted 2013-03-05T21:53:22.407

Reputation: 49 152

It does seem like any solution will require chaning the router, maybe having the mac do its duty. – Tal – 2013-03-06T07:37:36.797

0

The only option I can think of would be an app on the iPhone that knew when it was at home. iOS 4 added background location services with shape-based regions (sometimes also referred to as geo-fences. The app could be configured to call out to your server to trigger your desired behavior.

Of course this app would have to be written and then either approved by Apple or run in testing mode on your phone.

Brad Patton

Posted 2013-03-05T21:53:22.407

Reputation: 9 939

I live in a city and geoloc can't get precise enough for my uses. :( – Tal – 2013-03-06T07:35:33.337

0

Using the windows version of Airport Utility, you can enable the system logs. I'm sure that there is a system logging utility that creates actions when certain logs are transmitted. When the computer logs in, set an action corresponding with that system log.

JohnnyVegas

Posted 2013-03-05T21:53:22.407

Reputation: 2 820