FORUMS
Remove All Ads from XDA

[GUIDE][Difficulty: Advanced] Create a Hotspot Monitor to Watch Who's Connected

833 posts
Thanks Meter: 1,866
 
By MishaalRahman, Editor in Chief on 10th March 2016, 06:09 AM
Post Reply Email Thread
If you use a WiFi hotspot, you might be interested in monitoring how many devices and which devices are still connected to it. This is useful for when you're sharing your hotspot with friends or family. There is no real way to do this easily in Android, but with some clever shell commands, variable manipulation, and database searching, we can do so using Tasker!

Disclaimer: this is a profile created by redditor StillAzure over on the /r/tasker forum. I have taken the liberty to add comments explaining each step of the process as well as make a few changes to make it work on devices that his implementation does not work on.

Prerequisites
  1. Root Access
  2. Snackbar Tasker Plugin. This is what handles the pop-ups telling you what devices are connected. Not necessary but if you want to just import and forget just install it anyways.
  3. AutoNotification. This handles the notification telling you how many devices are connected by creating a persistent notification.
  4. The IEEE OUI database. Download it at http://standards-oui.ieee.org/oui.txt. I've found that this download server is slow and prone to time-out, so try it a few times until it fully downloads. Move it to /sdcard/Tasker. The redditor's task downloads it automatically but again it could fail and you wouldn't know without a progress bar telling you so.

Instructions


First profile will be the hotspot monitor profile (this is my own creation separate from the redditor's because his method did not trigger the profile):


  1. Create a new profile and name it Hotspot Monitor.
  2. Create an Event context and go to System --> Intent Received. Set Action to:
    Code:
    android.net.wifi.WIFI_AP_STATE_CHANGED
    Leave everything else blank.
  3. Enter the task creation, but leave the name blank.
  4. Task --> If. If %wifi_state eq 13. This means the hotspot is active.
  5. Variables --> Variable Set. Set %Hotspot to 1.
  6. Task --> Else.
  7. Plugin --> AutoNotification Cancel. Id: 55555. This will cancel the persistent notification from the hotspot monitor if the hotspot disconnects.
  8. Variables --> Variable Set. Set %Hotspot to 0. This means the hotspot has disconnected.
  9. Task --> End If.
Here's a screenshot of the task:


Next, we'll set up the task that actually looks up the manufacturer of the device connected to your hotspot by using its MAC ID.
  1. Create a task and name it "MAC Lookup"
  2. File --> Test File. Type: Modified. Data: Tasker/oui.txt. Store Result In: %MODIFIED. Check "continue task after error."
  3. Task --> If. If %err Set. Basically, if error is set, it means you don't have the database in the folder, so we'll need to download it.
  4. Plugin --> AutoNotification. Title: OUI Database not found! Text: Downloading the database... Id: Database. Persistent: true.
  5. Task --> Goto. Type: Action Label. Label: DOWNLOAD.
  6. Task --> End If.
  7. Variables --> Variable Set. Name %TODAY to %DATE.
  8. Variables --> Variable Convert. Name %TODAY, Function "Date Time to Seconds."
  9. Variables --> Variable Set. Name %SINCE to (%MODIFIED - %TODAY)/24/60/60. Check "Do Math." This is basically figuring out how many days it has been since the oui.txt has been last modified.
  10. Task --> If. Set it to if %SINCE > 14. If it's been more than 2 weeks since the database has been modified, we'll update it.
  11. Plugin --> AutoNotification. Title: OUI Database outdated! Text: Updating the database... Id: Database. Persistent: true.
  12. Net --> HTTP Get. Sever:Port set to http://standards-oui.ieee.org/oui.txt Make the file output to Tasker/oui.txt
  13. Plugin --> AutoNotification Cancel. Id: Database
  14. Plugin --> AutoNotification. Title: Database has been downloaded. Text: You can now swipe away this notification. Id: Database.
  15. Task --> End If.
  16. Variables --> Variable Clear. Name %MANU. This clears the current array of manufacturer IDs if it's already set (so we'll only get the most currently connected devices to our hotspot).
  17. Variables --> Array Clear. Name %MANU. Same idea.
  18. Code --> Run Shell. Run this command:
    Code:
    ip neigh show dev wlan0 | grep -i -e reachable -e delay | grep -o' ..\:..\:..'
    Check "Use Root", Store Output In %CLIENTS, and Store Errors in %error. Check "Continue Task after Error". This action basically gets the currently connected devices' MAC addresses and puts it into an array.
  19. Task --> If. If %error is Set. Meaning no devices are connected.
  20. Alert --> Flash. Text: Zero clients were found.
  21. Task --> Stop. Exit the task.
  22. Task --> End If.
  23. Variables --> Variable Split. Name: %CLIENTS. Leave Splitter blank.
  24. Task --> For. Variable is %for and Items are 2:%CLIENTS(#). Here, we're looping through each connected MAC ID and using our OUI database to look up and determine what manufacturer it belongs to.
  25. Variables --> Variable Convert. Name %CLIENTS(%for). Function: To Upper Case.
  26. Variables --> Variable Search Replace. Variable: %CLIENTS(%for), Search set to : (a colon), check Replace Matches, and for Replace With make it a blank space.
  27. Code --> Run Shell. Here's the command:
    Code:
    sed -n '/%CLIENTS(%for)/ p' /sdcard/Tasker/oui.txt
    Check Use Root, Store Output In %MANU(%for) and check Continue Task after Error.
  28. Variables --> Variable Section. Name %MANU(%for) From 23, Length 100. Cut out all the extraneous data.
  29. Task --> End For.

Here's screenshots of the task:





Next, we'll set up the profile that triggers when the hotspot is confirmed to be on.


  1. Create a new profile and name it "Hotspot Connected."
  2. Create a new State context and go to Variables --> Variable Value. Set it to when %Hotspot eq 1.
  3. Create a new task, but you don't need to name it anything.
  4. Task --> Perform Task. Name: MAC Lookup.
  5. Variables --> Variable Set. Name %PPLCOUNT to %CLIENTS(#)-1. This gets us how many clients are connected.
  6. Task --> If. If %CLIENTS(2) !Set. Meaning nobody is connected.
  7. Variables --> Variable Set. Name: %msg to <font color=yellow>No one's there!
  8. Task --> Else
  9. Variables --> Variable Set. Name: %msg to <font color=red>%PPLCOUNT <font color=white>people are still connected!
  10. Task --> End If.
  11. Variables --> Variable Join. Name %MANU, Joiner is , (a comma). This turns the manufacturer array into a comma-separated list.
  12. Plugin --> AutoNotification. Title: Warning! Text: Your hotspot is still on! %msg Action on Touch: CLIENTS. Id: 55555. Persistent: true. Title Expanded: List of Registered clients:
  13. That's it for this task. Exit out, and add a time context to this profile. Set it to every 5 minutes so your hotspot notification will update.

Here are screenshots of the task:



Finally, we will make the profile that triggers when you click on the notification.

  1. Create a new profile and name it Hotspot Information.
  2. Create an Event context and go to Plugin --> AutoNotification Event. Filter: CLIENTS.
  3. Create a task with no name. Go to the task editor.
  4. Plugin --> Snackbar Tasker Plugin --> Snackbar Without Button. Message: No one is connected to the hotspot! At the bottom, check If and set it to if %MANU !Set.
  5. Plugin --> Snackbar Tasker Plugin --> Snackbar Without Button. Message: Connected devices: %MANU. Check If at the bottom and set it to if %MANU is Set.

Here's a screenshot of the task:


I've attached the XMLs below. Please import them, but read through the labels and instructions above if you want to understand how these profiles work and how to edit them in the future.
Attached Files
File Type: xml Hotspot_Connected.prf.xml - [Click for QR Code] (12.5 KB, 710 views)
File Type: xml Hotspot_Information.prf.xml - [Click for QR Code] (20.8 KB, 402 views)
File Type: xml Hotspot_Monitor.prf.xml - [Click for QR Code] (6.0 KB, 402 views)
The Following 6 Users Say Thank You to MishaalRahman For This Useful Post: [ View ] Gift MishaalRahman Ad-Free
 
 
10th March 2016, 04:15 PM |#2  
Member
Thanks Meter: 14
 
More
Hi,
I am getting this error. Please see the attachment. Where am i going wrong?
Attached Thumbnails
Click image for larger version

Name:	Screenshot_2016-03-10-21-38-08.jpg
Views:	1238
Size:	239.2 KB
ID:	3678042  
The Following User Says Thank You to iamronin For This Useful Post: [ View ] Gift iamronin Ad-Free
10th March 2016, 10:45 PM |#3  
Junior Member
toronto
Thanks Meter: 2
 
More
did not get it with the auto notification. how do i change the name?
13th March 2016, 06:07 PM |#4  
Senior Member
Thanks Meter: 16
 
More
/u/StillAzure here, didn't notice this thread lol.

Quote:
Originally Posted by jayzero76

did not get it with the auto notification. how do i change the name?

What name again?

Quote:
Originally Posted by iamronin

Hi,
I am getting this error. Please see the attachment. Where am i going wrong?

It means there's no client connected. Are you sure there are any?
15th March 2016, 09:15 AM |#5  
venus342a's Avatar
Senior Member
Flag Kolkata
Thanks Meter: 128
 
Donate to Me
More
If you are rooted, try arcais netcut (cant link because i am new) which helps you to check who is connected to your network and also lets you kill the connection (Even if you are on someone elses connection) [WORKS IN ANDROID, IOS, MAC WINDOWS , LINUX . 100% TESTED]
Hope this helps!
The Following 2 Users Say Thank You to venus342a For This Useful Post: [ View ] Gift venus342a Ad-Free
24th April 2016, 02:33 AM |#6  
Senior Member
Thanks Meter: 44
 
More
Getting following error in Mac lookup task

EDIT
that's my bad
28th April 2016, 04:47 AM |#7  
Spookymyo's Avatar
Senior Member
Flag Morristown, TN
Thanks Meter: 206
 
More
Where's the MAC Lookup task? You've got everything else to import except it.
Post Reply Subscribe to Thread

Tags
connected, hotspot, monitor, tasker

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes