Last active
April 14, 2023 13:39
-
-
Save sgrodzicki/3b3552edf9e0e849d756a80343403007 to your computer and use it in GitHub Desktop.
UniFi Discovery in Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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