Unifi device tracker filling up with hundreds of unknown mac-addresses. Dont track new clients?

Hi shbatm this is amazing! I’ve been having so many issues with random macs showing up and the Tier 3 at UniFi was not very helpful. I’m running the latest version for everything right now but unfortunately I’m not very familiar on how to implement your script. Would you be kind to share like a step-by-step tutorial so I can add the script to the Cloud controller and automated? Let me know if you can help.

Thank you,

Steven

@cyberjson: Using the script should be pretty straightforward if you have a device running Linux with Python 3 available:

  1. Save the script somewhere (home directory is fine).
  2. Edit the username, password, cloud_key_ip, controller_port and site_name to match your controller info (first several lines at the top of the file).
  3. Test the script with:
    python3 /path/to/script/purge_clients.py
    
  4. Set up cron to run the script daily:
    crontab -e
    # Add this to the bottom of the file:
    @daily /usr/bin/python3 /path/to/script/purge_clients.py
    # Save!
    

Thank you you’re amazing! I guess I can use my Raspberry Pi :slight_smile: Is there a way to run it directly in the Unifi CloudKey?

Not sure; I don’t have a cloud key. It should run on anything that has network access to the controller/key so a RPi would work fine.

Awesome thanks again!

I did this but I got a syntax error line 13:

#!/usr/bin/env python3
import requests
from urllib.parse import urljoin

username = “username”
password = r"password"

cloud_key_ip = “192.168.1.2”
controller_port = 8443
site_name = “Controller”

base_url = “https://{192.168.1.2}:{8443}”.format(
cloud_key_ip=cloud_key_ip, controller_port=controller_port

Error is: Traceback (most recent call last):
File “/home/pi/Desktop/purge_clients.py”, line 13, in
cloud_key_ip=cloud_key_ip, controller_port=controller_port
IndexError: tuple index out of range

Don’t update the base_url line. It’ll get the values from everything else.

Thanks again for your suggestions. I got:

Successfully logged in

Retrieve client list

0 clients identified for purge

purge complete

It has anything to do with using a CloudKey gen2+?

I had to modify your script because I am running on the UDM-Base (’/api/auth/login’ for login, ‘/proxy/network’ added in front of the other API calls). I am able to retrieve macs, but when I call the

payload = {"cmd": "forget-sta", "macs": macs}
url = urljoin(base_url, "/proxy/network/api/s/{site_name}/cmd/stamgr".format(site_name=site_name))
resp = sess.post(url, json=payload)

I get a 404 response status “Not Found”. Any ideas on how to fix that?

Did you ever get this going? I get the same response.

@cyberjson @ManFromKC

I made this yesterday: https://github.com/wbradmoore/unifi-cleanup

It is working with controller version 6.0.45 on my Cloud Key gen2, but it should work on other devices.

For reference, these are the types of records it deletes:

2 Likes