Skip to content

Instantly share code, notes, and snippets.

@sgrodzicki
Last active April 14, 2023 13:39
Show Gist options
  • Save sgrodzicki/3b3552edf9e0e849d756a80343403007 to your computer and use it in GitHub Desktop.
Save sgrodzicki/3b3552edf9e0e849d756a80343403007 to your computer and use it in GitHub Desktop.
UniFi Discovery in Dart
import 'dart:io';
void main() {
var discoveryPort = 10001;
var discoveryBroadcast = InternetAddress('255.255.255.255');
var discoveryMulticast = InternetAddress('233.89.188.1');
RawDatagramSocket.bind(InternetAddress.anyIPv4, discoveryPort).then((RawDatagramSocket udpSocket) {
udpSocket.broadcastEnabled = true;
udpSocket.listen((e) {
Datagram? dg = udpSocket.receive();
if (dg != null) {
print(dg.data);
}
});
List<int> helloPacket = [2, 8, 0, 0];
udpSocket.send(helloPacket, discoveryBroadcast, discoveryPort);
udpSocket.send(helloPacket, discoveryMulticast, discoveryPort);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment