(Auch wenn ich hier kommerziellen Produkte erwähne werde ich weder dafür bezahlt, oder habe sonstige Vorteile, nur für den Fall das einer weint).

Ein typisches Problem beim Smart Home ist die Anwesenheitserkennung. Typischerweise kann man das nicht nur an einem Parameter festmachen. Da die meisten Menschen ihr Handy/Smart Phone mitnehmen wenn sie außer Haus gehen ist dies ein ganz guter Indikator. Wichtig, das ganze funktioniert nur wenn das Handy eine fixe Mac Adresse verwendet, dies muss z.B. unter IOS explizit eingestellt werden (Private WLAN-Adressen in iOS 14, iPadOS 14 und watchOS 7 verwenden – Apple Support). Der Ansatz hier hat den Vorteil das nur eine Verbindung im Physical Layer vorhanden sein muss, d.h. auch wenn das Handy im Energiesparmodus gehalten wird und nicht auf Pings reagiert ist der Physische Layer noch mit dem AP verbunden und die MAC Adresse dem AP bekannt. Da ASUS beim XT8 scheinbar ein OpenWrt Flavor verwendet ist hier auch das tool wl vorhanden mit dem sich Informationen der WLAN Schnittstelle auslesen lassen. Das auslesen erflogt via SSH, ist nicht ganz die feine Art, aber es Funktioniert ganz gut.

Für die SSH Verbindung ist die GitHub – phpseclib/phpseclib: PHP Secure Communications Library notwendig. Diese muss entsprechend im Script Ordern abgelegt werden.

 

Die Mac Adressen werden als Array gespeichert.

Das ganze sollte auch mit anderen OpenWrt AP/Router funktionieren. SSH muss in der Weboberfläche aktiviert werden, wenn noch nicht geschehen. In falle eines Mesh Wifis müssen alle Knoten mit GetMacs abgefragt werden.

 

<?php
require_once 'Net/SSH2.php';
$ifs=array('eth4','eth5','eth6','wl0.1','wl1.1','wl2.0');
$res=getMacs('192.168.88.252',$ifs);
$user1Mac=sscanf("12:34:56:78:9A:BC","%x:%x:%x:%x:%x:%x");
if(findMac($res,$user1Mac))
{
    print("User1 Mac found");
}
//read mac adresses from XT8
function getMacs($host,$ifs)
{
    $username = 'username';
    $password = 'password'; 
    
    $ssh = new NET_SSH2($host);
    //connect to SSH
        if (!$ssh->login($username, $password)) {
            die('Login Failed');
        }
        else{
            $ar=array();
            //Itterate through interfaces
            foreach($ifs as $if)
            {
                $command = ' wl -i '.$if.' assoclist';
                $output = $ssh->exec($command);
                //Interpret output
                $ar_b=readMacs($output);
                //merge mac address arays to the current existing ones
                $ar=array_merge($ar,$ar_b);
            }
            return($ar);
    }
}
//Reads the string buffer returned form wl -i if assoclist
//Each mac has its own line, so split by n and use sscanf to read the mac into array
function readMacs($macs)
 {
     $strs=explode("\n",$macs);
     $retVal = array();
     $ind=0;
     foreach($strs as $str)
     {   
         if($str!="")
         {
            $mac=sscanf($str,"assoclist %x:%x:%x:%x:%x:%x");
            $retVal[$ind]=$mac;
            $ind++;
         }
        
     }
     return($retVal);

 }

//find a dedicated mac address in a list of mac addresses
function findMac($array, $s_mac)
{
    foreach($array as $mac)
    {
        $ind=0;
        if(count($mac)==count($s_mac))
        {
            $ind=0;
            $inter=true;
            foreach($mac as $digit)
            {
                
                if($digit!=$s_mac[$ind])
                {
                    $inter=false;
                }
                $ind++;
                
            }
            if($inter==true)
            {
                return(true);
            }
        }
    }
    return(false);
}

marcus

Name: Marcus von Wilamowitz-Moellendorff Birth Year: 1981 Material Status: Married Hobbies: Blogging, Technology, Photography Education Industrial Electronic Technician Dipl. Inf. (FH) MSc (Practical Computer Science) MBA (Focus on Engineering Management) Focus of Work: Be a good example as elected team lead from/for my team Agile Development processes for safety relevant EE Systems (ISO 26262) EE System Development Tool Development Working Groups: VDV IP-KOM-ÖV WG for EN13149 7-9 ITxPT Professions: Autonomous Vehicle EE Architecture related (somehow the same or similar Project) Since 01/2018 Head of R&D/CTO @ HFM (Technical Focus on EE Architectur and Software for Self Driving Mobility Vehicles) 07/2017-01/2018 EE System Architect @ IBEO 07/2016-07/2017 Head off EE for Olli Project/Local Motors, technical lead in Germany Vehicle EE Architecture and Software Development 10/2011-07/2016 EE System Architect Lead CV and Product Manager 01/2003-10/2011 Hard and Software Developer @ Epislon Focus on Consulting/Vehicle Integration
Close Menu