diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index d03774b..a903524 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -8,6 +8,9 @@ name: Dart on: pull_request: branches: [ "main", "dev" ] + paths-ignore: + - '**/**.md' + - 'donation/**' concurrency: group: ${{ github.head_ref || github.run_id }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a1863f..7583fb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # Change Log +## 4.0.2 +1. Separated logs for example and library + ## 4.0.1 -1. Fixex path problem for dart and flutter sdk +1. Fixed path problem for dart and flutter sdk ## 4.0.0 ### Breaking changes diff --git a/example/lib/README.md b/example/lib/README.md new file mode 100644 index 0000000..f5e7e99 --- /dev/null +++ b/example/lib/README.md @@ -0,0 +1 @@ +Check examples/lib/main.dart \ No newline at end of file diff --git a/example/lib/example_utils.dart b/example/lib/example_utils.dart new file mode 100644 index 0000000..a2ecae2 --- /dev/null +++ b/example/lib/example_utils.dart @@ -0,0 +1,15 @@ +import 'package:logging/logging.dart'; + +final examplesLog = Logger("network_tools_examples"); + +void enableExampleLogging() { + Logger.root.level = Level.FINE; + Logger.root.onRecord.listen((record) { + if (record.loggerName == examplesLog.name) { + // ignore: avoid_print + print( + '${record.time.toLocal()}: ${record.level.name}: ${record.loggerName}: ${record.message}', + ); + } + }); +} diff --git a/example/lib/main.dart b/example/lib/main.dart new file mode 100644 index 0000000..dc0756a --- /dev/null +++ b/example/lib/main.dart @@ -0,0 +1,5 @@ +void main() { + print("Run host scan : 'dart example/lib/scan/host_scan.dart'"); + print("Run port scan : 'dart example/lib/scan/port_scan.dart'"); + print("Run mdns scan : 'dart example/lib/scan/mdns_scan.dart'"); +} diff --git a/example/host_scan.dart b/example/lib/scan/host_scan.dart similarity index 72% rename from example/host_scan.dart rename to example/lib/scan/host_scan.dart index 3911be6..7d6088d 100644 --- a/example/host_scan.dart +++ b/example/lib/scan/host_scan.dart @@ -1,8 +1,9 @@ import 'package:logging/logging.dart'; -import '../lib/network_tools.dart'; -import '../lib/src/network_tools_utils.dart'; +import 'package:network_tools/network_tools.dart'; +import '../example_utils.dart'; -void main() async { +Future main() async { + enableExampleLogging(); await configureNetworkTools('build'); String subnet = '192.168.0'; //Default network id for home networks @@ -15,7 +16,7 @@ void main() async { // or You can also get address using network_info_plus package // final String? address = await (NetworkInfo().getWifiIP()); - log.fine("Starting scan on subnet $subnet"); + examplesLog.fine("Starting scan on subnet $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. @@ -24,7 +25,7 @@ void main() async { // firstHostId: 1, // lastHostId: 254, progressCallback: (progress) { - log.finer('Progress for host discovery : $progress'); + examplesLog.finer('Progress for host discovery : $progress'); }, ); @@ -32,10 +33,10 @@ void main() async { (final host) async { //Same host can be emitted multiple times //Use Set instead of List - log.fine('Found device: ${await host.toStringFull()}'); + examplesLog.fine('Found device: ${await host.toStringFull()}'); }, onDone: () { - log.fine('Scan completed'); + examplesLog.fine('Scan completed'); }, ); // Don't forget to cancel the stream when not in use. } diff --git a/example/mdns_scan.dart b/example/lib/scan/mdns_scan.dart similarity index 85% rename from example/mdns_scan.dart rename to example/lib/scan/mdns_scan.dart index de73468..53d5466 100644 --- a/example/mdns_scan.dart +++ b/example/lib/scan/mdns_scan.dart @@ -1,10 +1,12 @@ import 'package:network_tools/network_tools.dart'; +import '../example_utils.dart'; Future main() async { + enableExampleLogging(); await configureNetworkTools('build'); for (final ActiveHost activeHost in await MdnsScanner.searchMdnsDevices()) { final MdnsInfo? mdnsInfo = await activeHost.mdnsInfo; - print( + examplesLog.fine( 'Address: ${activeHost.address}, Port: ${mdnsInfo!.mdnsPort}, ServiceType: ${mdnsInfo.mdnsServiceType}, MdnsName: ${mdnsInfo.getOnlyTheStartOfMdnsName()}, Mdns Device Name: ${mdnsInfo.mdnsSrvTarget}\n', ); } diff --git a/example/port_scan.dart b/example/lib/scan/port_scan.dart similarity index 73% rename from example/port_scan.dart rename to example/lib/scan/port_scan.dart index f1e3593..54d494c 100644 --- a/example/port_scan.dart +++ b/example/lib/scan/port_scan.dart @@ -1,8 +1,9 @@ import 'package:logging/logging.dart'; -import '../lib/src/network_tools_utils.dart'; import 'package:network_tools/network_tools.dart'; +import '../example_utils.dart'; -void main() async { +Future main() async { + enableExampleLogging(); await configureNetworkTools('build'); String subnet = '192.168.0'; //Default network id for home networks @@ -11,7 +12,7 @@ void main() async { final netId = interface?.networkId; if (netId != null) { subnet = netId; - log.fine('subnet id $subnet'); + examplesLog.fine('subnet id $subnet'); } // [New] Scan for a single open port in a subnet @@ -19,25 +20,25 @@ void main() async { // Similarly set [lastHostId] and scan will end at this host in the network. final stream2 = HostScanner.scanDevicesForSinglePort( subnet, - 22, + 53, progressCallback: (progress) { - log.finer('Progress for port discovery on host : $progress'); + examplesLog.finer('Progress for port discovery on host : $progress'); }, ); stream2.listen( (activeHost) { - log.fine( + examplesLog.fine( '[scanDevicesForSinglePort]: Found device : ${activeHost.toString()}'); final OpenPort deviceWithOpenPort = activeHost.openPorts[0]; if (deviceWithOpenPort.isOpen) { - log.fine( + examplesLog.fine( '[scanDevicesForSinglePort]: Found open port: ${deviceWithOpenPort.port} on ${activeHost.address}', ); } }, onDone: () { - log.fine('Port Scan completed'); + examplesLog.fine('Port Scan completed'); }, ); // Don't forget to cancel the stream when not in use. @@ -45,7 +46,7 @@ void main() async { final addr = interface?.ipAddress; if (addr != null) { target = addr; - log.fine("Target is $target"); + examplesLog.fine("Target is $target"); } PortScanner.scanPortsForSingleDevice( @@ -54,18 +55,19 @@ void main() async { // startPort: 1, endPort: 9400, progressCallback: (progress) { - log.finer('Progress for port discovery : $progress'); + examplesLog.finer('Progress for port discovery : $progress'); }, ).listen( (activeHost) { final OpenPort deviceWithOpenPort = activeHost.openPorts[0]; if (deviceWithOpenPort.isOpen) { - log.fine('Found open port: ${deviceWithOpenPort.port}'); + examplesLog.fine( + 'Found open port: ${deviceWithOpenPort.port} on device $target'); } }, onDone: () { - log.fine('Port Scan from 1 to 9400 completed'); + examplesLog.fine('Port Scan from 1 to 9400 completed'); }, ); } diff --git a/example/main.dart b/example/main.dart deleted file mode 100644 index 09e0de3..0000000 --- a/example/main.dart +++ /dev/null @@ -1,5 +0,0 @@ -void main() { - print("Run host scan : 'dart example/host_scan.dart'"); - print("Run port scan : 'dart example/port_scan.dart'"); - print("Run mdns scan : 'dart example/mdns_scan.dart'"); -} diff --git a/lib/network_tools.dart b/lib/network_tools.dart index bb17766..2dc54e7 100644 --- a/lib/network_tools.dart +++ b/lib/network_tools.dart @@ -5,6 +5,7 @@ import 'package:get_it/get_it.dart'; import 'package:logging/logging.dart'; import 'package:network_tools/injectable.dart'; import 'package:network_tools/src/device_info/vendor_table.dart'; +import 'package:network_tools/src/network_tools_utils.dart'; import 'package:network_tools/src/services/arp_service.dart'; export 'src/device_info/net_interface.dart'; @@ -33,18 +34,20 @@ Future configureNetworkTools( bool enableDebugging = false, }) async { _enableDebugging = enableDebugging; + _dbDirectory = dbDirectory; if (enableDebugging) { Logger.root.level = Level.FINE; Logger.root.onRecord.listen((record) { - // ignore: avoid_print - print( - '${record.time.toLocal()}: ${record.level.name}: ${record.loggerName}: ${record.message}', - ); + if (record.loggerName == log.name) { + // ignore: avoid_print + print( + '${record.time.toLocal()}: ${record.level.name}: ${record.loggerName}: ${record.message}', + ); + } }); } configureDependencies(); - _dbDirectory = dbDirectory; - final arpServiceFuture = await _getIt().open(); - await arpServiceFuture.buildTable(); + final arpService = await _getIt().open(); + await arpService.buildTable(); await VendorTable.createVendorTableMap(); } diff --git a/pubspec.yaml b/pubspec.yaml index 1070e8d..e3eaf2e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: network_tools description: Networking Tools library which can help you discover open ports, devices on subnet and many other things. -version: 4.0.1 +version: 4.0.2 issue_tracker: https://github.com/osociety/network_tools/issues repository: https://github.com/osociety/network_tools