quickIcmpScanSync method

Future<List<Host>> quickIcmpScanSync(
  1. String subnet, {
  2. int firstIP = 1,
  3. int lastIP = 255,
  4. Duration timeout = const Duration(seconds: 1),
})

Discovers network devices in the given subnet. Works on iOS platform.

Uses ICMP as icmpScan method, but internally has faster implementation and doesn't use streams.

This method may block the main thread, so on platform other than iOS it is recommended to use quickIcmpScanAsync instead.

Implementation

Future<List<Host>> quickIcmpScanSync(
  String subnet, {
  int firstIP = 1,
  int lastIP = 255,
  Duration timeout = const Duration(seconds: 1),
}) async {
  final hostFutures = <Future<Host?>>[];

  for (var currAddr = firstIP; currAddr <= lastIP; ++currAddr) {
    final hostToPing = '$subnet.$currAddr';

    hostFutures.add(
      _pingHost(
        hostToPing,
        timeout: timeout.inSeconds,
      ),
    );
  }

  // Executing this synchronously causes the main thread to freeze.
  final resolvedHosts = await Future.wait(hostFutures);

  return resolvedHosts
      .where((element) => element != null)
      .cast<Host>()
      .toList();
}