Code Monkey home page Code Monkey logo

network_tools's Introduction

Network Tools

pub package

Network Tools Supported

  1. Host Scanner

  2. Port Scanner

    1. Single
    2. Range
    3. Custom

Partly Work:

  1. Mdns Scanner

Import package in your app

import 'package:network_tools/network_tools.dart'; 

Usage

Host Scanner

 String address = '192.168.1.12';
  // or You can also get address using network_info_plus package
  // final String? address = await (NetworkInfo().getWifiIP());
  final String subnet = address.substring(0, address.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]);

Mdns Scanner

    for (final ActiveHost activeHost in await MdnsScanner.searchMdnsDevices()) {
      final MdnsInfo? mdnsInfo = activeHost.mdnsInfo;
      print(
        'Address: ${activeHost.address}, Port: ${mdnsInfo!.mdnsPort}, ServiceType: ${mdnsInfo.mdnsServiceType}, MdnsName: ${mdnsInfo.getOnlyTheStartOfMdnsName()}',
      );
    }

Run examples

  1. Run host scan : dart example/host_scan.dart
  2. Run port scan : dart example/port_scan.dart
  3. Run mdns scan : dart example/mdns_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

network_tools's People

Contributors

git-elliot avatar guyluz11 avatar stausssi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.