lan_scanner
Dart / Flutter包,允许发现本地网络(LAN)中的网络设备。
注意:此库旨在用于 C 类网络。
此项目是对已存在的 ping_discover_network 的重构,但它已不再维护。
入门
将包添加到您的 pubspec.yaml
lan_scanner: ^2.0.0
导入库
import 'package:lan_scanner/lan_scanner.dart';
创建一个类的实例并调用
quickScan() 或 preciseScan() 方法
final port = 80;
final subnet = "192.168.0";
final timeout = Duration(seconds: 5);
final scanner = LanScanner();
final stream = scanner.preciseScan(
subnet,
timeout: timeout,
progressCallback: (ProgressModel progress) {
print('${progress.percent * 100}% 192.168.0.${progress.currIP}');
},
);
stream.listen((DeviceModel device) {
if (device.exists) {
print("Found device on ${device.ip}:${device.port}");
}
});
如果您不知道子网是什么,您可以使用 network_info_plus 然后使用 ipToSubnet() 函数。
var wifiIP = await (NetworkInfo().getWifiIP())
var subnet = ipToSubnet(wifiIP);
功能和 Bug
请在 问题跟踪器 上提交功能请求和 bug。