ping_discover_network_plus 0.0.5 copy "ping_discover_network_plus: ^0.0.5" to clipboard
ping_discover_network_plus: ^0.0.5 copied to clipboard

Library that allows to ping IP subnet and discover network devices. Could be used to find printers and other devices and services in a local network.

ping_discover_network_plus #

Pub

Dart/Flutter library that allows to ping IP subnet and discover network devices.

Could be used to find printers (for example, on port 9100) and any other devices and services in local network.

The device should be connected to a Wi-Fi network. wifi package allows to get the local IP address / network subnet.

The library tested on both, Android and iOS platforms.

[pub.dev page] | [Documentation]

Getting Started #

Check complete examples in /example folder.

Discover available network devices in a given subnet on a given port:

import 'package:ping_discover_network_plus/ping_discover_network_plus.dart';

// NetworkAnalyzer.discover pings PORT:IP one by one according to timeout.
// NetworkAnalyzer.discover2 pings all PORT:IP addresses at once.

const port = 80;
final stream = NetworkAnalyzer.discover2(
  '192.168.0', port,
  timeout: Duration(milliseconds: 5000),
);

int found = 0;
stream.listen((NetworkAddress addr) {
  if (addr.exists) {
    found++;
    print('Found device: ${addr.ip}:$port');
  }
}).onDone(() => print('Finish. Found $found device(s)'));

Get local ip and discover network devices:

import 'package:wifi_info_plugin_plus/wifi_info_plugin_plus.dart';
import 'package:ping_discover_network_plus/ping_discover_network_plus.dart';

final ip = (await WifiInfoPlugin.wifiDetails)?.ipAddress ?? 'NO IP DETECTED';
final String subnet = ip.substring(0, ip.lastIndexOf('.'));
final int port = 80;

final stream = NetworkAnalyzer.discover2(subnet, port);
stream.listen((NetworkAddress addr) {
  if (addr.exists) {
    print('Found device: ${addr.ip}');
  }
});

Discover available network devices in a given subnet on a given port range:

import 'package:ping_discover_network_plus/ping_discover_network_plus.dart';

void checkPortRange(String subnet, int fromPort, int toPort) {
  if (fromPort > toPort) {
    return;
  }

  print('port ${fromPort}');

  final stream = NetworkAnalyzer.discover2(subnet, fromPort);

  stream.listen((NetworkAddress addr) {
    if (addr.exists) {
      print('Found device: ${addr.ip}:${fromPort}');
    }
  }).onDone(() {
    checkPortRange(subnet, fromPort + 1, toPort);
  });
}

checkPortRange('192.168.0', 400, 410);
6
likes
160
points
912
downloads

Publisher

verified publishermarcus.brasizza.com

Weekly Downloads

Library that allows to ping IP subnet and discover network devices. Could be used to find printers and other devices and services in a local network.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, wifi_info_plugin_plus

More

Packages that depend on ping_discover_network_plus