Skip to content

Instantly share code, notes, and snippets.

@andrewgho
Last active June 21, 2020 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewgho/4233036fe7f3b798ad2fc82aa3d88085 to your computer and use it in GitHub Desktop.
Save andrewgho/4233036fe7f3b798ad2fc82aa3d88085 to your computer and use it in GitHub Desktop.
unifi_clients.sh - dump list of clients from UniFi Cloud Key
#!/bin/sh
# unifi_clients.sh - dump list of clients from UniFi Cloud Key
# Andrew Ho (andrew@zeuscat.com)
#
# https://ubntwiki.com/products/software/unifi-controller/api
USERNAME=redacted
PASSWORD=redacted
BASEURL=https://unifi-cloudkey-gen2:8443
curl -iks -d "{\"username\":\"$USERNAME\",\"password\":\"$PASSWORD\"}" "$BASEURL/api/login" |
sed -n 's/^Set-Cookie: //p' | sed 's/;.*$//' | xargs echo | tr ' ' ';' |
xargs -ICOOKIE curl -ks -b COOKIE "$BASEURL/api/s/default/stat/sta" |
jq '[.data[] | {name,hostname,ip,essid,is_wired,oui} | del(.[] | nulls)]' |
jq 'sort_by(.name,.hostname,.ip)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment