Skip to content

The library allows to ping network devices in an IP subnet and therefore dicover them. Could be used to find printers and other services.

License

Notifications You must be signed in to change notification settings

ziarehmank/ping_discover_network

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ping_discover_network

Changed to null safety.

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/ping_discover_network.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/wifi.dart';
import 'package:ping_discover_network/ping_discover_network.dart';

final String ip = await Wifi.ip;
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/ping_discover_network.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);

About

The library allows to ping network devices in an IP subnet and therefore dicover them. Could be used to find printers and other services.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 74.9%
  • Ruby 14.3%
  • Objective-C 4.9%
  • Shell 3.5%
  • Java 2.4%