UniFiSharp 1.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package UniFiSharp --version 1.4.0                
NuGet\Install-Package UniFiSharp -Version 1.4.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UniFiSharp" Version="1.4.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UniFiSharp --version 1.4.0                
#r "nuget: UniFiSharp, 1.4.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install UniFiSharp as a Cake Addin
#addin nuget:?package=UniFiSharp&version=1.4.0

// Install UniFiSharp as a Cake Tool
#tool nuget:?package=UniFiSharp&version=1.4.0                

UniFiSharp

Bringing Ubiquiti UniFi Orchestration Automation to C#

UniFiSharp provides a basic C# API for Ubiquiti UniFi controllers, as well as an orchestration overlay to more easily visualize network topology and execute device commands. UniFiSharp also implements both v1 and v2 of the Ubiquiti discovery protocol for automated controller discovery.

As of UniFiSharp v1.1.0, the API surface has changed slightly to improve usability and maintainability; please read the usage documentation below.

This project is written for any .NET application that can consume a .NET Standard 2.0 library. All future contributions are planned to continue to enable cross-platform use.

Basic API Usage

The UniFiApi class provides all base-level API features:

// Instantiate the API object
using (var api = new UniFiSharp.UniFiApi(new Uri("https://controller:8443"), "username", "password", "siteName"))
{
    // Manually calling .Authenticate() forces the API to proactively authenticate.
    // Otherwise, the request will be automatically authenticated upon receiving an unauthorized error.
	await api.Authenticate();

	// ... for example, enumerate all UniFi devices known by the controller:
    IEnumerable<UniFiSharp.Json.JsonNetworkDevice> uniFiDevices = await api.NetworkDeviceList();

	// ... or to upgrade the firmware on a device:
	await api.NetworkDeviceUpgrade("01:23:45:67:89:AB");
}

UBNT Cloud

The UniFiApi class can also be used with UBNT Cloud-hosted services by changing the base URI to match the UBNT Cloud format:

var api = new UniFiSharp.UniFiApi(new Uri("https://demo.ubnt.com/"), "username", "password")

Note: At the time of this writing, Ubiquiti's cloud will accept the above demo credentials and allow the user to work in a sandboxed, artificial environment. This demo setup includes approximately 130 UniFi devices and 1200 clients.

Orchestration Usage

In order to make this system more developer-friendly, it also ships with an orchestration overlay that wraps the UniFiApi object and associates common information to their devices, as well as attempting to converge a basic topology based on the device objects:

// Instantiate the API object
using (var api = new UniFiSharp.UniFiApi(new Uri("https://controller:8443"), "username", "password", "siteName"))
using (var orchestrator = new UniFiSharp.Orchestration.UniFiOrchestrator(api))
{    
    // Calls api.Refresh() under the hood
    await orchestrator.Refresh();
    
    // ... for example, retrieve the first AP and turn on its locator for 5 seconds:
    await orchestrator.InfrastructureDevices.First(d => d is UniFiSharp.Orchestration.Devices.AccessPointInfrastructureNetworkedDevice).Locate(5000);
    
    // ... or to browse the network topology from the edge inwards, start from:
    INetworkedDevice networkRoot = orchestrator.TopologicalRoot;
    
    // ... or to create a new port forward (to 192.168.1.100:TCP/80):
    await orchestrator.PortForwards.Add(
              UniFiSharp.Orchestration.Models.PortForward.Create(
                  name: "abc",
                  proto: "tcp",
                  source: "any",
                  sourcePort: 80,
                  dest: "192.168.1.100",
                  destPort: 80
              ));
}

Disclaimer

This software is not affiliated with nor supported by Ubiquiti Networks and is offered under the license as described in LICENSE. This software should never be used in a production environment without exhaustive, independent testing.

The "U" logo component used is strictly for product identification purposes only, and is protected by fair use.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.5.2 545 11/21/2022
1.5.1 409 10/31/2022
1.5.0 465 5/13/2022
1.4.1 421 4/25/2022
1.4.0 355 9/18/2021
1.3.0 451 4/2/2021
1.1.0 1,101 4/11/2018