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

Search This thread

MishaalRahman

Editor in Chief
Nov 2, 2015
1,038
2,118
www.xda-developers.com
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):

1T6n2rA.jpg


  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:
1KgMpYn.jpg


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:
AmwTHdh.jpg

b5I2kME.jpg

GhmFn7v.jpg

c3N2HNZ.jpg


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

ihb0ET9.jpg


  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:
kWlqYmw.jpg

NpuaspC.jpg


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


  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:
4kAVgDR.jpg


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.
 

Attachments

  • Hotspot_Connected.prf.xml
    12.5 KB · Views: 748
  • Hotspot_Information.prf.xml
    20.8 KB · Views: 433
  • Hotspot_Monitor.prf.xml
    6 KB · Views: 431

iamronin

Senior Member
Aug 1, 2015
92
17
Hi,
I am getting this error. Please see the attachment. Where am i going wrong?
 

Attachments

  • Screenshot_2016-03-10-21-38-08.jpg
    Screenshot_2016-03-10-21-38-08.jpg
    239.2 KB · Views: 1,283
  • Like
Reactions: bulsara

Top Liked Posts

  • There are no posts matching your filters.
  • 5
    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):

    1T6n2rA.jpg


    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:
    1KgMpYn.jpg


    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:
    AmwTHdh.jpg

    b5I2kME.jpg

    GhmFn7v.jpg

    c3N2HNZ.jpg


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

    ihb0ET9.jpg


    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:
    kWlqYmw.jpg

    NpuaspC.jpg


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


    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:
    4kAVgDR.jpg


    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.
    2
    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!
    1
    Hi,
    I am getting this error. Please see the attachment. Where am i going wrong?
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone