搜索插件、代码仓与 APP 分类

插件详情v6.0.18

network_tools

网络工具库,可帮助您发现开放端口、子网上的设备以及其他许多功能。

AndroidiOSmacOSWindowsLinux
近 30 天下载
1万
喜欢数
57
Pub 分数
160

安装插件

flutter pub add network_tools

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

network_tools 包是一个 Flutter 实用工具库,旨在帮助进行网络发现和诊断。它使开发者能够扫描子网、检测开放端口,并识别本地网络上的设备。该库支持跨平台使用,适用于 Android、iOS、macOS、Windows 和 Linux,非常适合需要低级别网络交互的应用程序。该库通过平台通道利用原生平台功能,确保在各种环境中的可靠性能。它特别适用于网络监控、物联网设备检测和故障排除工具。其轻量级设计和简洁的 API 使得专注于网络功能的开发者能够轻松集成。

适合场景

  • 本地网络扫描
  • 子网上的设备发现
  • 端口扫描用于诊断
  • 物联网设备检测
  • 网络故障排除

主要特点

  • 跨平台支持
  • 子网扫描
  • 开放端口检测
  • 设备枚举
  • 平台渠道集成

适合对象

  • 网络诊断应用
  • 物联网管理工具
  • 系统监控工具
  • 网络分析的开发工具
  • 教育网络项目

使用建议

  • 需要适当的系统权限
  • 在某些平台上可能需要根/管理员权限
  • 性能因网络规模而异
  • 限于本地网络范围
  • 取决于底层操作系统的网络功能

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Cross Platform Network Tools

pub package Dart Code Coverage codecov

Network Tools Supported

  1. Host Scanner

    1. Search all devices on subnet
    2. Get mac address of devices on Linux, macOS and Windows.
    3. Search devices for a specific port open.
  2. Port Scanner

    1. Single Port scan
    2. Range
    3. Custom

Partly Work:

  1. Mdns Scanner

Network Tools Flutter package

Please check network_tools_flutter package for extensive support to features on different platforms.

Import package in your app

import 'package:network_tools/network_tools.dart';

Configure network tools in main function

For dart native
Future<void> main() async {
  await configureNetworkTools('build', enableDebugging: true);
  runApp(const MyApp());
}
For flutter apps
Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // It's necessary to pass correct path to be able to use this library.
  final appDocDirectory = await getApplicationDocumentsDirectory();
  await configureNetworkTools(appDocDirectory.path, enableDebugging: true);
  runApp(const MyApp());
}

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 = HostScannerService.instance.getAllPingableDevices(subnet, firstHostId: 1, lastHostId: 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';
  PortScannerService.instance.scanPortsForSingleDevice(target, startPort: 1, endPort: 1024,
      progressCallback: (progress) {
    print('Progress for port discovery : $progress');
  }).listen((ActiveHost event) {
    if (event.openPorts.isNotEmpty) {
      print('Found open ports : ${event.openPorts}');
    }
  }, onDone: () {
    print('Scan completed');
  });
  //2. Single
  bool isOpen = (await PortScanner.isOpen(target, 80)) == null;
  //3. Custom
  PortScanner.customDiscover(target, portList: const [22, 80, 139]);
Mdns Scanner
  for (final ActiveHost activeHost in await MdnsScannerService.instance.searchMdnsDevices()) {
    final MdnsInfo? mdnsInfo = await 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

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.

    Librepay
    Donate using Liberapay
  3. Support me on Ko-Fi

    ko-fi

Inspired from ping_discover_network

所属分类

依赖

依赖清单 12 项

源码仓库

使用此插件的项目