Skip to main content

Detect If Your Device Is Connected To Wifi using Python

Have you ever wanted to see the list of devices connected to your local home network?
Linux provides a cool solution to list all the devices connected to your network using arp scanning.

You need to follow these simple steps:(These are for Linux)

1) Make sure you have arp-scan package installed (if not use sudo apt-get install arp-scan command in terminal to install the package)

2) In order to verify type sudo arp-scan --interface=wlan0 --localnet in terminal. You will probably see the list of devices connected to your local network using wifi.

This sets our base and now we can move on to write our python script to detect particular devices and see there status if its connected to wifi or not.

NOTE: We need to know the mac address of the devices we want to track.

Now Let's create a new python script and name it anything you like and paste this code 

I named mine detectDeviceOnWifi.py




Now run your script using sudo python detectDeviceOnWifi.py in terminal and see the output.
If the device with the mac address mentioned is connected to the same network then it will print out Device found.

This was just a small script which can be used to target various applications.
It can be used to monitor kids devices whenever they are connected to wifi at night.
Or can be used to turn on/off lights whenever you enter/leave your office.

However, these scenarios require some embedded device(Arduino/RPi) which could possibly send out signals to control other devices.

So the possibilities are endless with just this small piece of script.

I hope you guys like it and maybe you can also post your ideas in the comments section below. 

Happy Coding!
  


Comments

Popular posts from this blog

Build Optimization Editor Tool(Android)(WIP)

Note: This version works only with Unity 5.0+ Have you faced problems when dealing with multiple audio files and changing their settings to optimize the build size. Now, with this editor script you can optimize the audio files in the assets folder by selecting only those files which needs modification. In future update you can optimize texture settings for android as well. Current Version -Audio Compression Upcoming Version -Support Texture Compression Download Plugin Here

Create Unity Custom Editor - Basics (Part 1)

In this basic lessons we will be going to create our own custom inspectors inside unity. Before we dive in lets get to know what custom inspectors are A custom inspector is basically an overridden inspector window which can help artist and designers to interact with the inspector in a more user friendly manner. It also helps to create a neat looking inspector for your scripts attached to gameobjects. So lets get started with the initial project setup    Steps to follow: 1) Start a fresh project 2) Create a folder name Scripts This will hold all the scripts(typically monobehaviour) which will be attached to a gameobject in the scene. 3) Create a folder name Editor ( Note : it should be the exact same name ) This will hold all the Editor scripts and Unity will automatically detect weather or not the project contains any editor scripts for component scripts. With this done we have the basic fundamental structu...

Create Unity Custom Editor - Basics (Part 4)

In the last lesson we linked our custom editor script with our test script. In this lesson we are going to create some custom GUI elements. So lets get started with that 1) Jump to the Editor Script and comment out the DrawDefaultInspector() so that we can start adding our own custom elements Lets get started with introducing some GUI elements that we can create inside the inspector The most basic one is a label 2) We will be using EditorGUILayout class to show our label inside the inspector. This class has got tons of other types of functions which you can use Goto this link and checkout the other functions available inside the EditorGUILayout class. I would recommend to spend sometime on those functions provided and try to implement all of those so that you can get an idea of how you can use different GUI elements to represent custom inspectors. 3) Now when we go back to unity we will see a label showing inside our inspector. Now this concludes that ...