osociety / network_tools

Networking Tools library which can help you discover open ports, devices on subnet and many other things.
https://pub.dev/packages/network_tools
BSD 3-Clause "New" or "Revised" License
45 stars 13 forks source link

scanDevicesForSinglePort ping iOS not working #107

Closed rainbowMehBerdaya closed 1 year ago

rainbowMehBerdaya commented 1 year ago

HostScanner.scanDevicesForSinglePort for iOS not working

From dependency documentation I think this should add this package dart_ping_ios

as said in dart_ping docs

To use dart_ping on iOS, add the dart_ping_ios package as a dependency and register the iOS plugin before initializing Ping. For more detailed docs, see the dart_ping_ios package. Note that the iOS plugin requires the flutter sdk. (this is why it is not integrated into dart_ping directly)

Thank you for the package!

git-elliot commented 1 year ago

I guess its the time we work on network_tools_flutter package @guyluz11 . Since we cannot add dart_ping_ios in network_tools as a dependency

guyluz11 commented 1 year ago

Cool, maybe there are some flutter-only packages that we can use to add new functionality to more stuff

rainbowMehBerdaya commented 1 year ago

Why can't you guys add dart_ping_ios to the network_tools package? I tried running it with this code, and it worked, but I'm not sure if it's the most practical solution.

static Stream<ActiveHost> scanDevicesForSinglePort(
    String subnet,
    int port, {
    int firstHostId = defaultFirstHostId,
    int lastHostId = defaultLastHostId,
    Duration timeout = const Duration(milliseconds: 2000),
    ProgressCallback? progressCallback,
    bool resultsInAddressAscendingOrder = true,
  }) async* {
    if (Platform.isIOS) {
      DartPingIOS.register();
    }

    final int lastValidSubnet =
        _validateAndGetLastValidSubnet(subnet, firstHostId, lastHostId);
    final List<Future<ActiveHost?>> activeHostOpenPortList = [];
    final StreamController<ActiveHost> activeHostsController =
        StreamController<ActiveHost>();

    for (int i = firstHostId; i <= lastValidSubnet; i++) {
      final host = '$subnet.$i';
      activeHostOpenPortList.add(
        PortScanner.connectToPort(
          address: host,
          port: port,
          timeout: timeout,
          activeHostsController: activeHostsController,
        ),
      );
    }

    if (!resultsInAddressAscendingOrder) {
      yield* activeHostsController.stream;
    }

    int counter = firstHostId;
    for (final Future<ActiveHost?> openPortActiveHostFuture
        in activeHostOpenPortList) {
      final ActiveHost? activeHost = await openPortActiveHostFuture;
      if (activeHost != null) {
        yield activeHost;
      }
      progressCallback?.call(
        (counter - firstHostId) * 100 / (lastValidSubnet - firstHostId),
      );
      counter++;
    }
  }
guyluz11 commented 1 year ago

dart_ping_ios

It looks like dart ping ios use flutter_icmp_ping as a dependency and it flutter only

image

One thing that is important to us is to keep this package support of dart native. In order to solve issues like yours we are thinking of opening a new package that supports only flutter use network_tools for most of the work and solves some of the problems that can only get resolved using a flutter package.

git-elliot commented 1 year ago

@rainbowMehBerdaya you add below code in your main class, it will work. Don't forget to add dart_ping_ios as dependency in your project until network_tools_flutter is published.

  if (Platform.isIOS) {
      DartPingIOS.register();
  }

We stick to what @guyluz11 said

One thing that is important to us is to keep this package support of dart native.

rainbowMehBerdaya commented 1 year ago

Yes, I have already tried that and it's running well I have shared the code in my previous comment. Thank you.

Also, it's up to you guys if you want to close it. Cheers 🍻

git-elliot commented 1 year ago

We will keep this open to remind us in finishing network_tools_flutter package

git-elliot commented 1 year ago

@rainbowMehBerdaya network_tools_flutter package is now available for testing purpose - https://github.com/osociety/network_tools_flutter. Please try and give feedback by reopening this issue.