Syed Jahanzaib Personal Blog to Share Knowledge !

January 3, 2017

Ubiquiti Unifi Notes & Odd methods of acquiring Info

Filed under: Ubiquiti — Syed Jahanzaib / Pinochio~:) @ 9:49 AM


1- Set controller address in UniFi Access Point via SSH putty

to get information about access point , issue


to set access point controller address, use


whereas is the controller server IP.

1.2- Odd method to acquire total number of active WiFi Clients

Bash script to acquire some info via UniFi controller like active number of WiFi clients connected with different UniFi AP LR in the company.

# Script to query active clients by curl from unifi controller
# Syed jahanzaib / aacable . wordpress . com / aacable at hotmail dot com
# 2nd-January-2017
#set -x
# UniFi Controller IP and Port
# pattern to match to count active clients using string matching

# First Login to controller via CURL
curl -s "https://$IP:$PORT/api/login" --data-binary '{"username":"admin","password":"CONTROLLERPASSWORD","strict":true}' --compressed --insecure -c $COOKIE > /dev/null

# Download Statistics from controller using CURL
curl -s --insecure -b $COOKIE -c $COOKIE "https://$IP:$PORT/api/s/default/stat/sta" > $TMP_HOLDER

# Count active users by pattern match,  what an odd method, may not work correctly, but so far working for me
ACTIVE=`cat $TMP_HOLDER | grep -o $PATTERN | wc -l`
echo $ACTIVE
echo $ACTIVE

Result in command …



CFG file for MRTG …

# Unifi Controller - WiFi Active WiFi Clients - syed.jahanzaib
Target[unifi_wifi_active_users]: `/temp/`
Title[unifi_wifi_active_users]: Active Wifi Clients via Unifi Controller
PageTop[unifi_wifi_active_users]: <H1>Active Wifi Clients via Unifi Controller</H1>
MaxBytes[unifi_wifi_active_users]: 50000
Colours[unifi_wifi_active_users]: B#8888ff,B#0813B7,B#5398ff,B#0813B7
Options[unifi_wifi_active_users]: growright,nopercent,gauge,integer,nobanner,printrouter,pngdate,noo
LegendI[unifi_wifi_active_users]: Active Wifi Users
YLegend[unifi_wifi_active_users]: Active Wifi Users
Legend1[unifi_wifi_active_users]: Active Wifi Users
#Unscaled[unifi_wifi_active_users]: dwmy

MRTG Graph for Active WiFi Clients via UniFi Controller …


  •  – – – – – – – – –
  •  – – – – – – – – –
  •  – – – – – – – – –
  •  – – – – – – – – –

Following are some snapshots from the UniFi Controller for some comparison that script is working accurate so far …
(However it is still under observation to monitor its accuracy result / zaib)



2- Odd method to acquire total number of Active Access Points Vs Down [Registered in UniFi Controller]

Bash script to acquire total number of registered access points (unifi AP-LR) and there status as well to compare Active vs down.

# Script to query active clients by curl from unifi controller
#set -x
curl -s "https://$IP:$PORT/api/login" --data-binary '{"username":"admin","password":"CONTROLLERPASSWORD","strict":true}' --compressed --insecure -c $COOKIE > /dev/null
curl -s --insecure -b $COOKIE -c $COOKIE "https://$IP:$PORT/api/s/default/stat/device" > $TMP_HOLDER
ACTIVE=`cat $TMP_HOLDER | grep -o $PATTERN | wc -l`
DOWN=`grep -oP '\"state\" : \K[^ ]*' $TMP_HOLDER | grep 0 | wc -l`
echo $DOWN
echo $ACTIVE

Result in command …

[Total access points  vs DOWN]


CFG file for MRTG …

# Unifi Controller - UniFi AP-LR - Active Access Points vs DOWN
Target[unifi_ap_total_vs_down]: `/temp/`
Title[unifi_ap_total_vs_down]: UniFi AP-LR - Active Access Points vs DOWN
PageTop[unifi_ap_total_vs_down]: <H1>UniFi AP-LR - Active Access Points vs DOWN</H1>
MaxBytes[unifi_ap_total_vs_down]: 5000
Colours[unifi_ap_total_vs_down]: B#0000FF,R#FF0000,B#0000FF,R#FF0000
Options[unifi_ap_total_vs_down]: growright,nopercent,gauge,integer,nobanner,printrouter,pngdate
LegendI[unifi_ap_total_vs_down]: Active AP --&gt;
LegendO[unifi_ap_total_vs_down]: Down AP --&gt;
YLegend[unifi_ap_total_vs_down]: Active vs Down
Legend1[unifi_ap_total_vs_down]: Active Access Points
Legend2[unifi_ap_total_vs_down]: Down Access Points
#Unscaled[unifi_ap_total_vs_down]: dwmy

MRTG Graph for Active WiFi AP DEVICES via UniFi Controller …


3# Upgrade UniFi AP LR Access Point via SSH/CLI

We have few unifi AP-LR  Wireless Access Points in our company which are connected with the Unifi Controller ver on windows 2008 r2 / x64 server. For some unknown reasons I was unable to upgrade the access point’s firmware from the controller. Therefore I upgraded all AP’s via SSH method which is posted below …

First download the appropriate firmware and upload it to some web server. (at the time of upgrading the latest firmware version was , you make sure to download latest one available)
Select your model / download from following link …

[Luckily I had local web server available so I simply put this file into my /var/www folder (for ubuntu)]


Now login in the access point via SSH , and issue this command


Make sure to change the path or ip according to your network. Once its upgraded it rebooted and new Firmware was

I will post more info later …

Syed Jahanzaib

%d bloggers like this: