5

I'm working on a project based on Intel Edison(Running Debian based Ubilinux).I need Edison to execute some code whenever,my android phone(running CM11) connects to the same WiFi as the Edison.How can I detect the presence of my phone in Edison? I have tried the following.

1.Pinging: But the problem is that router assigns different IP's every time because of DHCP.So,I will not be knowing the IP address of my phone. Is there any way to ping based on device's MAC address?

2. I thought of broadcasting a special discovery packet from my phone,whenever it gets connected to the WiFi.But,I don't know where to start with this approach.

0andriy
  • 4,183
  • 1
  • 24
  • 37
Heisenberg
  • 185
  • 3
  • 10
  • 1
    this is not a python-question. It's a question about the wifi-protocol and its exposure within a given OS. Once you know what to do there, you need to do it from python - but that will be a different question. – deets Mar 27 '15 at 14:22
  • @deets I agree.But,second part of your comment explains why I tagged "python" :) – Heisenberg Mar 27 '15 at 14:40
  • @Heisenberg if either question helped you (and arp is the way to go, so they both did..) click on the tick next to the question. – pstanton Apr 30 '15 at 05:47
  • To solve the first part of your problem, you could assign a reserved IP to your device in your router settings. – John Red Dec 05 '22 at 07:35

2 Answers2

3

Arprequest allows you to "arping" MAC addresses within Python:

from arprequest import ArpRequest
>>> ar = ArpRequest('10.0.0.1', 'eth0')
>>> ar.request()
True

Pop that in a loop and you've got a MAC monitor.

As alternative, you could take an event based approach and use Scapy to monitor for DHCP requests from your Android device and take an action when it sees it.

Alastair McCormack
  • 26,573
  • 8
  • 77
  • 100
2

Finding the mac-address would probably work. Basically you can run the arp command to see what mac-address matches which IP. There's a question on doing that here:

Obtain MAC Address from Devices using Python

Community
  • 1
  • 1
John Montgomery
  • 8,868
  • 4
  • 33
  • 43