Go Down

Topic: MAC address scan on wifi network - ESP8266 (Read 14704 times) previous topic - next topic

SteveShaw

I'd like to use a ESP8266 connected to my in house Wifi, to scan the network for connected devices so that i can determine who is in the house by whether their phone MAC address is seen on the network. Then i can use this to make decision by who is home for other Automation projects.

I've looked around but not really found anything that could help me.

It might be easier to use a Raspberry Pi (i believe by using PING and ARP) running as a server to do this then use that as the control system, but would really like to use the ESP8266

Any ideas how if / how to do this with the ESP8266 ?

Stinde

I have same goal, but no solution so far.

ESP8266Ping library ( https://github.com/dancol90/ESP8266Ping ) doesn't give all the response parameters.


simonliu009

I have the same goal too. I searched around and found nothing.
But apparently it is a basic function in IoT device.

gpsmikey

Typically, the MAC address is only visible on each end of a "hop" in a packet so if you are going from some device via wifi through the router to some other device, the MAC address you would see would be from your device and the router.  The router will typically have a table of IP addresses and associated MAC addresses for those devices that it has handed out an IP address to via DHCP, but I don't think it tracks the MAC addresses of things with fixed IP addresses for example (granted, most portable devices like phones will be getting an address via DHCP). It has been 15+ years since I went through the Cisco class, so things are a bit fuzzy ...
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3

mrburnette

#4
Oct 15, 2016, 10:45 pm Last Edit: Oct 15, 2016, 11:00 pm by mrburnette
I'm sorry my response has come over 30 days, but getting MAC for both client and Access Point associations and broadcasts was a bit more of an issue than I initially thought.

Still, there is now code that will gather this data.

I hope you find the proof-of-concept useful.  Members with ESP8266 forum ID's may wish to track this thread too:
http://www.esp8266.com/viewtopic.php?f=29&t=12127

@SteveShaw, if the code is adequate, would you please mark the title [Solved].


Ray

Sample output over serial-USB:
Code: [Select]


1.5.3(aec24ac9)
ESP8266 mini-sniff 
by Ray Burnette http://www.hackster.io/rayburne/projects
Type:   /-------MAC------/---- SSID----/  /----MAC---/  Chnl  RSSI
BEACON: <=============== [HOME-01FC-2.4]  84002da251d8    6    -93
BEACON: <=============== [   TardisTime]  1afe34a08bc9    8    -80
BEACON: <=============== [  xfinitywifi]  84002da251da    6    -92
DEVICE: 18fe34f977a0 ==> [   TardisTime]  1afe34a08bc9    8    -91
BEACON: <=============== [             ]  fa8fca34e26c   11    -86
BEACON: <===============      HOME-30C2]  5c571a0730c0   11    -85
DEVICE: 6002b4484f2d ==>    Unknown/Malformed packet 
BEACON: <=============== [             ]  52571a0730c0   11    -82
BEACON: <=============== [  xfinitywifi]  56571a0730c0   11    -88
BEACON: <=============== [   ATT8Q4z656]  b077acc4dfd0   11    -92
BEACON: <=============== [   ATTGH6Gs22]  1005b1d6ff90   11    -88
BEACON: <=============== [             ]  fa8fca95bad3   11    -94
BEACON: <=============== [             ]  92877c55b1c0   11    -93
DEVICE: 18fe34fdc2b8 ==> [   TardisTime]  1afe34a08bc9    8    -78
DEVICE: 6c71d970d1b7 ==> [   ATT8Q4z656]  01005e7ffffa   11    -94
BEACON: <=============== [             ]  84002da251d9    6    -90
BEACON: <=============== [    HOME-B1C2]  94877c55b1c0   11    -97
BEACON: <=============== [   ATT4P3G9f8]  1c1448777420   11    -94
DEVICE: 28b2bd6b9d29 ==> [   ATT8Q4z656]  ffffffffffff   11    -91
DEVICE: e0f847252fbc ==> [   ATT8Q4z656]  ffffffffffff   11    -91
DEVICE: a4773369c4d8 ==> [    HOME-30C2]  88cb8787697a   11    -91
BEACON: <=============== [  xfinitywifi]  96877c55b1c0   11    -92

mcnobby

http://www.youtube.com/user/Recovered
http://www.smartshow.lighting

riker1

Hi

anyone having an example how to implement etharp gratious arp?
thanks

gewkwn

#7
Jun 29, 2019, 10:05 pm Last Edit: Jun 29, 2019, 11:25 pm by gewkwn


maybe my  code is help you ..

thanks for original code of Ricardo Oliveira and Skickar

Code: [Select]
Friend Detector by Ricardo Oliveira, forked by Skickar 9/30/2018

1)https://github.com/RicardoOliveira/FriendDetector
2)https://github.com/skickar/FriendDetector



extra Edited from George konstantinidis in Kavala Hellas 27/6/2019
{

The function of this code is to read nearby Wi-Fi traffic in the form of packets. These packets are compared
to a list of MAC addresses we wish to track, and if the MAC address of a packet matches one on the list, we
print the active stage of devices compared to mac address  of list
*/

/*
 *   On edit by George konstantinidis add serial debuging
 *   to write status on serial monitor
 *   On version 0.3 add some delay "DELAY2" for safety
 *   on connection.
 *  
 *   in my area for DELAY2 =13636 time is about 300sec
 */


#include "./esppl_functions.h"

// list of my devices
#define LIST_SIZE 2                              

// mac adress of devices
uint8_t friendmac[LIST_SIZE][ESPPL_MAC_LEN] = {
   {0x42, 0x3e, 0x8e, 0x1a, 0xfd, 0xfa}
  ,{0x02, 0x06, 0x4d, 0x83, 0x1a, 0x1c}
  };
/*
 * This is your friend's name list
 * put them in the same order as the MAC addresses
 */
String friendname[LIST_SIZE] = {
   "neffos x1 max"
  ,"Shield"
  };

bool VisibleDevices[LIST_SIZE] ={false,false};        // find or not in scanning for devices
bool VisibleDevicesOld[LIST_SIZE] ={false,false};     // value to compare with old value
int  VisibleDevicesTimer[LIST_SIZE] ={0,0};           // value to find then is pass time with out connection
bool VisibleDevicesTriger[LIST_SIZE] ={false,false};  // value to trigger then have change with VisibleDevices

bool VisibleDevicesConnect[LIST_SIZE]={false,false};  // value to print  olny one time then disconecting( after time)!!!
bool VisibleDevicesDisConnect[LIST_SIZE]={false,false};  // value to print olny one time then connecting !!!
int DELAY2=13636;                                         // time to delay

void setup() {
  Serial.begin(115200);

  esppl_init(cb);

  //some blink's
  pinMode(2, OUTPUT);          
  digitalWrite(2,LOW);
  delay(200);
  digitalWrite(2,HIGH);
  delay(200);
  digitalWrite(2,LOW);
  delay(200);
  digitalWrite(2,HIGH);
  delay(200);
}


 
bool maccmp(uint8_t *mac1, uint8_t *mac2) {  // compare mac address
  for (int i=0; i < ESPPL_MAC_LEN; i++) {
                  
    if (mac1[i] != mac2[i]) {
      return false;
    }
  }
  return true;
}

void cb(esppl_frame_info *info)    //Αναφερεται στο esppl_init(cb);  του Setup
  {

  for (int i=0; i<LIST_SIZE; i++)
    {
    // compare mac address with list  
    if (maccmp(info->sourceaddr, friendmac[i]) || maccmp(info->receiveraddr, friendmac[i]))
      {
      VisibleDevices[i]=true;
      VisibleDevicesTimer[i] =DELAY2;
      VisibleDevicesConnect[i]=true;
      }
    else
      { // this is for if the packet does not match any we are tracking
      VisibleDevices[i]=false;  
      }

    // trigger then value of VisibleDevices[i]  change
    if  (VisibleDevices[i]!=VisibleDevicesOld[i])
      {
      VisibleDevicesTriger[i]=true;
      }

    // messages triger
    if ((VisibleDevicesTimer[i]==DELAY2)&&(VisibleDevicesTriger[i]==true)&&(VisibleDevicesDisConnect[i]==false))
      {
      Serial.printf("\n%s is near! :)", friendname[i].c_str());
      VisibleDevicesDisConnect[i]=true;
      VisibleDevicesConnect[i]=true;
      }
    if ((VisibleDevicesTimer[i]==0) && (VisibleDevicesConnect[i]==true))
      {
      VisibleDevicesConnect[i]=false;
      Serial.printf("\n%s is Far far away .. :)", friendname[i].c_str());
      VisibleDevicesDisConnect[i]=true;
    
      }
    // procces for incoming messages  once for 100 times of DELAY2
    if (((VisibleDevicesTimer[i]%100)==0)&&(VisibleDevicesConnect[i]==true))
      {
      Serial.println(friendname[i]+" have no: "+ VisibleDevicesTimer[i]);
      }

    // Add function  
    //VisibleDevicesTimer[i] always >=0    
    if (VisibleDevicesTimer[i]<0)
      {
      VisibleDevicesTimer[i]=0;
      }    
    VisibleDevicesTimer[i]=VisibleDevicesTimer[i]-1;  
    }  // end for
  }  // end cb
    

void loop()
   {  
   esppl_sniffing_start();
   while (true)
     {
     for (int i = ESPPL_CHANNEL_MIN; i <= ESPPL_CHANNEL_MAX; i++ )
       {
       esppl_set_channel(i);
       while (esppl_process_frames()) {}
       }
     }  
          

   }

riker1


jtreg

I love this project, is there a simple way of returning the Serial.println data into a format so I can use to send via OSC? I dont want to mess up functions.h (I already tried!) - Has anyone done this...?

gewkwn

I don't understand what exactly you want ...



Go Up