ecki / net-tools

Linux base networking tools
GNU General Public License v2.0
248 stars 95 forks source link

FormatException: Missing extension byte (at offset 3) in Windows #30

Closed xmlspyspring closed 7 months ago

xmlspyspring commented 7 months ago

I ran the following code and got the following error:

code:

import 'package:network_tools/network_tools.dart';

import '../example_utils.dart';

Future<void> main() async {
  enableExampleLogging();
  await configureNetworkTools('build');

  String subnet = '192.168.1'; //Default network id for home networks

  final interface = await NetInterface.localInterface();
  // final netId = interface?.networkId;
  // if (netId != null) {
  //   subnet = netId;
  //   examplesLogger.fine('subnet id $subnet');
  // }

  // [New] Scan for a single open port in a subnet
  // You can set [firstHostId] and scan will start from this host in the network.
  // Similarly set [lastHostId] and scan will end at this host in the network.
  final stream2 = HostScannerService.instance.scanDevicesForSinglePort(
    subnet,
    53,
    progressCallback: (progress) {
      examplesLogger.finer('Progress for port discovery on host : $progress');
    },
  );

  stream2.listen(
    (ActiveHost activeHost) {
      examplesLogger
          .fine('[scanDevicesForSinglePort]: Found device : $activeHost');
      final OpenPort deviceWithOpenPort = activeHost.openPorts[0];
      if (deviceWithOpenPort.isOpen) {
        examplesLogger.fine(
          '[scanDevicesForSinglePort]: Found open port: ${deviceWithOpenPort.port} on ${activeHost.address}',
        );
      }
    },
    onDone: () {
      examplesLogger.fine('Port Scan completed');
    },
  ); // Don't forget to cancel the stream when not in use.

  // String target = '192.168.1.1';
  // final addr = interface?.ipAddress;
  // if (addr != null) {
  //   target = addr;
  //   examplesLogger.fine("Target is $target");
  // }

  // PortScannerService.instance.scanPortsForSingleDevice(
  //   target,
  //   // Scan will start from this port.
  //   // startPort: 1,
  //   endPort: 9400,
  //   progressCallback: (progress) {
  //     examplesLogger.finer('Progress for port discovery : $progress');
  //   },
  // ).listen(
  //   (activeHost) {
  //     final OpenPort deviceWithOpenPort = activeHost.openPorts[0];
  //
  //     if (deviceWithOpenPort.isOpen) {
  //       examplesLogger.fine(
  //         'Found open port: ${deviceWithOpenPort.port} on device $target',
  //       );
  //     }
  //   },
  //   onDone: () {
  //     examplesLogger.fine('Port Scan from 1 to 9400 completed');
  //   },
  // );
}

Error:

C:/a_dev/flutter-sdk/bin/cache/dart-sdk/bin/dart.exe --enable-asserts C:\Users\xmlspyspring\IdeaProjects\network_tools\example\lib\scan\port_scan.dart
2024-03-25 18:36:59.261617: FINE: network_tools_examples: [scanDevicesForSinglePort]: Found device : Address: 192.168.1.1, HostId: 1, Time: nullms, port: 53
2024-03-25 18:36:59.264387: FINE: network_tools_examples: [scanDevicesForSinglePort]: Found open port: 53 on 192.168.1.1
Unhandled exception:
FormatException: Missing extension byte (at offset 3)
#0      _Utf8Decoder.convertChunked (dart:convert-patch/convert_patch.dart:1845:7)
#1      _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:304:28)
#2      _Utf8ConversionSink.add (dart:convert/string_conversion.dart:300:5)
#3      _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:69:18)
#4      _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
#5      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#6      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#7      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#8      _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
#9      _StreamController._add (dart:async/stream_controller.dart:658:7)
#10     _StreamController.add (dart:async/stream_controller.dart:606:5)
#11     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#12     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#13     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#14     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
#15     _StreamController._add (dart:async/stream_controller.dart:658:7)
#16     _StreamController.add (dart:async/stream_controller.dart:606:5)
#17     _Socket._onData (dart:io-patch/socket_patch.dart:2447:41)
#18     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#19     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#20     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#21     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
#22     _StreamController._add (dart:async/stream_controller.dart:658:7)
#23     _StreamController.add (dart:async/stream_controller.dart:606:5)
#24     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1936:33)
#25     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1379:14)
#26     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#27     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#28     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#29     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)

Process finished with exit code 255

At first I thought it was a codepage problem, but I still reported this error after changing the code below:

In file lib/src/services/impls/host_scanner_service_impl.dart Line 110 change Ping(host, count: 1, timeout: timeoutInSeconds) to Ping(host, count: 1, timeout: timeoutInSeconds,forceCodepage: true)

ecki commented 7 months ago

I think you report against the wrong project.