network_tools 1.0.8 copy "network_tools: ^1.0.8" to clipboard
network_tools: ^1.0.8 copied to clipboard

Networking Tools library which can help you discover open ports, devices on subnet and many other things.

Network Tools #

pub package

Network Tools Supported

  1. Host Scanner

  2. Port Scanner

    1. Single
    2. Range
    3. Custom

What's not supported

  1. Mac Address of other devices on network

Import package in your app #

import 'package:network_tools/network_tools.dart'; 

Usage #

Host Scanner #

 String ip = '192.168.1.12';
  // or You can also get ip using network_info_plus package
  // final String? ip = await (NetworkInfo().getWifiIP());
  final String subnet = ip.substring(0, ip.lastIndexOf('.'));
  final stream = HostScanner.discover(subnet, firstSubnet: 1, lastSubnet: 50,
      progressCallback: (progress) {
    print('Progress for host discovery : $progress');
  });

  stream.listen((host) {
    //Same host can be emitted multiple times
    //Use Set<ActiveHost> instead of List<ActiveHost>
    print('Found device: ${host}');
  }, onDone: () {
    print('Scan completed');
  }); // Don't forget to cancel the stream when not in use.

Port Scanner #

  //1. Range
  String target = '192.168.1.1';
  PortScanner.discover(target, startPort: 1, endPort: 1024,
      progressCallback: (progress) {
    print('Progress for port discovery : $progress');
  }).listen((event) {
    if (event.isOpen) {
      print('Found open port : $event');
    }
  }, onDone: () {
    print('Scan completed');
  });
  //2. Single
  bool isOpen = PortScanner.isOpen(target,80);
  //3. Custom
  PortScanner.customDiscover(target, portList : const [22, 80, 139]);

Run examples #

  1. Run host scan : dart example/host_scan.dart
  2. Run port scan : dart example/port_scan.dart

Enable Debugging #

Add this code to your main.dart file

Logger.root.level = Level.FINE; //set to finest for detailed log
  Logger.root.onRecord.listen((record) {
    print(
        '${DateFormat.Hms().format(record.time)}: ${record.level.name}: ${record.loggerName}: ${record.message}');
  });

Sample App #

Vernet is the open source app built on top of this library. You can check out the code and implementation for more detailed use case of this package.

Support and Donate #

  1. Support this project by becoming stargazer of this project.

  2. Buy me a coffee.

    Bitcoin UPI
  3. Support me on Ko-Fi

    ko-fi

Inspired from ping_discover_network

34
likes
100
pub points
89%
popularity

Publisher

verified publisherfsoc13ty.blogspot.com

Networking Tools library which can help you discover open ports, devices on subnet and many other things.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

dart_ping, intl, logging, universal_io

More

Packages that depend on network_tools