[Tasker Tips & Tricks] MishaalRahman:
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

Root Access

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.

AutoNotification. This handles the notification telling you how many devices are connected by creating a persistent notification.

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):

Create a new profile and name it Hotspot Monitor.

Create an Event context and go to System --> Intent Received. Set Action to:

android.net.wifi.WIFI_AP_STATE_CHANGED

Leave everything else blank.

Enter the task creation, but leave the name blank.

Task --> If. If %wifi_state eq 13. This means the hotspot is active.

Variables --> Variable Set. Set %Hotspot to 1.

Task --> Else.

Plugin --> AutoNotification Cancel. Id: 55555. This will cancel the persistent notification from the hotspot monitor if the hotspot disconnects.

Variables --> Variable Set. Set %Hotspot to 0. This means the hotspot has disconnected.

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.

Create a task and name it "MAC Lookup"

File --> Test File. Type: Modified. Data: Tasker/oui.txt. Store Result In: %MODIFIED. Check "continue task after error."

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.

Plugin --> AutoNotification. Title: OUI Database not found! Text: Downloading the database... Id: Database. Persistent: true.

Task --> Goto. Type: Action Label. Label: DOWNLOAD.

Task --> End If.

Variables --> Variable Set. Name %TODAY to %DATE.

Variables --> Variable Convert. Name %TODAY, Function "Date Time to Seconds."

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.

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.

Plugin --> AutoNotification. Title: OUI Database outdated! Text: Updating the database... Id: Database. Persistent: true.

Net --> HTTP Get. Sever:Port set to http://standards-oui.ieee.org/oui.txt Make the file output to Tasker/oui.txt

Plugin --> AutoNotification Cancel. Id: Database

Plugin --> AutoNotification. Title: Database has been downloaded. Text: You can now swipe away this notification. Id: Database.

Task --> End If.

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).

Variables --> Array Clear. Name %MANU. Same idea.

Code --> Run Shell. Run this command:

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.

Task --> If. If %error is Set. Meaning no devices are connected.

Alert --> Flash. Text: Zero clients were found.

Task --> Stop. Exit the task.

Task --> End If.

Variables --> Variable Split. Name: %CLIENTS. Leave Splitter blank.

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.

Variables --> Variable Convert. Name %CLIENTS(%for). Function: To Upper Case.

Variables --> Variable Search Replace. Variable: %CLIENTS(%for), Search set to : (a colon), check Replace Matches, and for Replace With make it a blank space.

Code --> Run Shell. Here's the command:

sed -n '/%CLIENTS(%for)/ p' /sdcard/Tasker/oui.txt

Check Use Root, Store Output In %MANU(%for) and check Continue Task after Error.

Variables --> Variable Section. Name %MANU(%for) From 23, Length 100. Cut out all the extraneous data.

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.

Create a new profile and name it "Hotspot Connected."

Create a new State context and go to Variables --> Variable Value. Set it to when %Hotspot eq 1.

Create a new task, but you don't need to name it anything.

Task --> Perform Task. Name: MAC Lookup.

Variables --> Variable Set. Name %PPLCOUNT to %CLIENTS(#)-1. This gets us how many clients are connected.

Task --> If. If %CLIENTS(2) !Set. Meaning nobody is connected.

Variables --> Variable Set. Name: %msg to <font color=yellow>No one's there!

Task --> Else

Variables --> Variable Set. Name: %msg to <font color=red>%PPLCOUNT <font color=white>people are still connected!

Task --> End If.

Variables --> Variable Join. Name %MANU, Joiner is , (a comma). This turns the manufacturer array into a comma-separated list.

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:

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.

Create a new profile and name it Hotspot Information.

Create an Event context and go to Plugin --> AutoNotification Event. Filter: CLIENTS.

Create a task with no name. Go to the task editor.

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.

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.