Bart Simons

Bart Simons

Thoughts, stories and ideas.

Bart Simons



.net .net 5 .net core Apache C# CentOS LAMP NET Framework Pretty URLs Windows Server WireGuard access log add analysis android api at the same time authentication authorization automate automation azure azurerm backup bash basics batch bootstrap build capture cheat sheet chromium chroot class cli click to close code coverage code snippet command line commands compile compiling compression containers control controller controlling convert cpu usage create credentials csv csvparser curl data dd deployment desktop detect devices disable diskpart dism distributed diy docker dom changes dotnet core drivers ease of access encryption example export file transfer files fix folders framework generalize getting started ghost gui guide gunicorn gzip html html tables icewarp igd imagex import inotify install installation interactive ios iphone itunes java javascript jquery json kiosk kotlin linux live load data loading screen lock screen loopback audio lxc lxd lxml macos manage manually message messages minio mirrored mod_rewrite monitor monitoring mstest mutationobserver mysql net 5 nexmo nginx no oobe node node.js nodejs not installing notification notifications object storage on desktop one command openssl owncloud parallels parallels tools parse perfect philips hue play port forwarding powershell processing ps-spotify python quick raspberry pi record rip ripping rsync rtmp save save data sbapplication scraping script scripting scriptingbridge scripts security send server service sharedpreferences sms songs sonos spotify spotify api spotlight ssh stack streaming streamlink studio sudo swarm swift sync sysprep system audio systemd tables terminal testing tracking tutorial twilio ubiquiti ubuntu ubuntu 18.04 ui code unifi unlock unsplash source upnp uptime usb tethering wallpapers wasapi website websites webview windows windows 10 without itunes without oobe workaround xaml

Playing around with the Ubiquiti UniFi Controller

I found that today would be a great day to finally get an access point from Ubiquiti to improve my WiFi signal at home, while my intention was to keep my old wireless router in use for the wired and routing/DHCP/DNS stuff. So I went to the store and bought the UniFi AP AC Lite. The performance of this thing is pretty good so far, although I might get another one soon to cover the upper floor with better speeds over 5G as well. The cool thing about the UniFi series from Ubiquiti is that you can have all your UniFi devices managed with their software appliance, which I installed on a Linux Hyper-V VM.

Using cURL to fiddle around with the UniFi controller

cURL is a the tool that I used to build and create HTTP(S) requests to the UniFi controller. Google Chrome, my browser, has a feature that makes it easy to replay requests by generating full cURL commands that one could use directly from a bash shell.

Logging into the UniFi Controller using cURL

Logging into the controller with cURL was one of the easiest things to do. The page that handles the login action is https://controller:8443/api/login and only takes POST requests. You can login and save your cookies aswell by using the following command:

curl 'https://controller:8443/api/login' --data-binary '{"username":"usernamegoeshere","password":"passwordgoeshere","strict":true}' --compressed --insecure -c cookies.txt

If you get something returned that says OK, then you are successfully logged in!

Obtaining the network configuration
curl --insecure -b cookies.txt -c cookies.txt 'https://controller:8443/api/s/default/rest/networkconf' > output.json

Or, if you want to pass the output to a JSON processor directly:

curl --insecure -b cookies.txt -c cookies.txt 'https://controller:8443/api/s/default/rest/networkconf' | jq '.'
Get user groups
curl --insecure -b cookies.txt -c cookies.txt 'https://controller:8443/api/s/default/rest/usergroup' > output.json
Get UniFi devices
curl --insecure -b cookies.txt -c cookies.txt 'https://controller:8443/api/s/default/stat/device' > output.json
Get list of connected devices
curl --insecure -b cookies.txt -c cookies.txt 'https://controller:8443/api/s/default/stat/sta' > output.json

There are probably more things to do with the API, but I will figure that out later. Funny is that Ubiquiti doesn't actually have any official documentation for their API available.

Bart Simons

Bart Simons

View Comments