From dda59486da1b88fdc7b1f3d4cb63f3b20eb33102 Mon Sep 17 00:00:00 2001 From: git-elliot Date: Sun, 29 Jan 2023 01:33:05 +0530 Subject: [PATCH 1/3] Removed print calls and excluded example folder --- network_tools/analysis_options.yaml | 1 + .../get_srv_list_by_os/srv_list_linux.dart | 12 +++++++----- network_tools/lib/src/mdns_scanner/mdns_scanner.dart | 8 ++++++-- network_tools/lib/src/models/active_host.dart | 5 ++++- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/network_tools/analysis_options.yaml b/network_tools/analysis_options.yaml index 34b4773..fa699ff 100644 --- a/network_tools/analysis_options.yaml +++ b/network_tools/analysis_options.yaml @@ -21,6 +21,7 @@ analyzer: - "**/*.pbjson.dart" - "**/*.gr.dart" - "**/*.md" + - "example/**" linter: rules: diff --git a/network_tools/lib/src/mdns_scanner/get_srv_list_by_os/srv_list_linux.dart b/network_tools/lib/src/mdns_scanner/get_srv_list_by_os/srv_list_linux.dart index 1781569..fe82f6b 100644 --- a/network_tools/lib/src/mdns_scanner/get_srv_list_by_os/srv_list_linux.dart +++ b/network_tools/lib/src/mdns_scanner/get_srv_list_by_os/srv_list_linux.dart @@ -1,8 +1,10 @@ import 'dart:collection'; +import 'package:logging/logging.dart'; import 'package:process_run/shell.dart'; class SrvListLinux { + static final log = Logger("srv_list_linux"); static Future?> getSrvRecordList() async { final HashSet srvList = HashSet(); @@ -10,7 +12,7 @@ class SrvListLinux { srvList.addAll(await runAvahiBrowseCommand()); srvList.addAll(await runMdnsScanCommand()); } catch (e) { - print('Error:\n$e'); + log.severe('Error:\n$e'); } return srvList.toList(); } @@ -34,7 +36,7 @@ timeout 2s avahi-browse --all -p final String? resultStderr = error.result?.stderr.toString(); if (resultStderr != null && resultStderr.contains('No such file or directory')) { - print( + log.fine( 'You can make the mdns process better by installing `avahi-browse`', ); return []; @@ -58,7 +60,7 @@ timeout 2s avahi-browse --all -p } } } catch (e) { - print('Error getting info from avahi-browse\n$e'); + log.severe('Error getting info from avahi-browse\n$e'); } return srvListAvahi; } @@ -83,7 +85,7 @@ timeout 2s mdns-scan if (resultStderr == null || (resultStderr.contains('No such file or directory'))) { - print( + log.fine( 'You can make the mdns process better by installing `mdns-scan`', ); return []; @@ -104,7 +106,7 @@ timeout 2s mdns-scan } } } catch (e) { - print('Error getting info from mdns-scan\n$e'); + log.severe('Error getting info from mdns-scan\n$e'); } return srvListMdnsScan; } diff --git a/network_tools/lib/src/mdns_scanner/mdns_scanner.dart b/network_tools/lib/src/mdns_scanner/mdns_scanner.dart index 33f6c3b..3f027e7 100644 --- a/network_tools/lib/src/mdns_scanner/mdns_scanner.dart +++ b/network_tools/lib/src/mdns_scanner/mdns_scanner.dart @@ -1,3 +1,4 @@ +import 'package:logging/logging.dart'; import 'package:multicast_dns/multicast_dns.dart'; import 'package:network_tools/network_tools.dart'; import 'package:network_tools/src/mdns_scanner/get_srv_list_by_os/srv_list.dart'; @@ -12,6 +13,8 @@ class MdnsScanner { /// TODO: https://github.com/flutter/flutter/issues/97210 /// TODO: In some cases we resolve this missing functionality using /// TODO: specific os tools. + static final log = Logger('active_host'); + static Future> searchMdnsDevices({ bool forceUseOfSavedSrvRecordList = false, }) async { @@ -102,8 +105,9 @@ class MdnsScanner { listOfActiveHost.add(tempHost); } } catch (e) { - print( - 'Error finding ip of mdns record ${foundMdns.ptrResourceRecord.name} srv target ${foundMdns.mdnsSrvTarget} , will add it with ip 0.0.0.0\n$e'); + log.severe( + 'Error finding ip of mdns record ${foundMdns.ptrResourceRecord.name} srv target ${foundMdns.mdnsSrvTarget} , will add it with ip 0.0.0.0\n$e', + ); final ActiveHost tempHost = ActiveHost( internetAddress: InternetAddress('0.0.0.0'), mdnsInfoVar: foundMdns, diff --git a/network_tools/lib/src/models/active_host.dart b/network_tools/lib/src/models/active_host.dart index deb4423..14f1d46 100644 --- a/network_tools/lib/src/models/active_host.dart +++ b/network_tools/lib/src/models/active_host.dart @@ -1,4 +1,5 @@ import 'package:dart_ping/dart_ping.dart'; +import 'package:logging/logging.dart'; import 'package:network_tools/src/models/mdns_info.dart'; import 'package:network_tools/src/models/open_port.dart'; import 'package:universal_io/io.dart'; @@ -92,6 +93,8 @@ class ActiveHost extends Comparable { Duration? get responseTime => _pingData.response?.time; String get address => internetAddress.address; + final log = Logger('active_host'); + @override int get hashCode => address.hashCode; @@ -151,7 +154,7 @@ class ActiveHost extends Comparable { // throw exception. // We don't need to print this crash as it is by design. } else { - print('Exception here: $e'); + log.severe('Exception here: $e'); } } return null; From 9ab494b2e4d0eb4d2b6e1531398498fdd5fe8572 Mon Sep 17 00:00:00 2001 From: git-elliot Date: Sun, 29 Jan 2023 01:52:31 +0530 Subject: [PATCH 2/3] Combined all loggers to one place --- network_tools/example/host_scan.dart | 1 - network_tools/example/port_scan.dart | 2 +- network_tools/lib/network_tools.dart | 1 - .../src/mdns_scanner/get_srv_list_by_os/srv_list_linux.dart | 3 +-- network_tools/lib/src/mdns_scanner/mdns_scanner.dart | 3 +-- network_tools/lib/src/models/active_host.dart | 4 +--- network_tools/lib/src/netowrk_tools_utils.dart | 3 +++ 7 files changed, 7 insertions(+), 10 deletions(-) create mode 100644 network_tools/lib/src/netowrk_tools_utils.dart diff --git a/network_tools/example/host_scan.dart b/network_tools/example/host_scan.dart index ffbf070..1562e8a 100644 --- a/network_tools/example/host_scan.dart +++ b/network_tools/example/host_scan.dart @@ -10,7 +10,6 @@ void main() { ); }); - final log = Logger('host_scan'); const String address = '192.168.1.1'; // or You can also get address using network_info_plus package // final String? address = await (NetworkInfo().getWifiIP()); diff --git a/network_tools/example/port_scan.dart b/network_tools/example/port_scan.dart index 88311d8..f13edf5 100644 --- a/network_tools/example/port_scan.dart +++ b/network_tools/example/port_scan.dart @@ -9,7 +9,7 @@ void main() { '${DateFormat.Hms().format(record.time)}: ${record.level.name}: ${record.loggerName}: ${record.message}', ); }); - final log = Logger('port_scan'); + const String address = '192.168.1.1'; // or You can also get address using network_info_plus package // final String? address = await (NetworkInfo().getWifiIP()); diff --git a/network_tools/lib/network_tools.dart b/network_tools/lib/network_tools.dart index 7509198..60809b5 100644 --- a/network_tools/lib/network_tools.dart +++ b/network_tools/lib/network_tools.dart @@ -1,7 +1,6 @@ library network_tools; //TODO: add dartdocs - export 'src/host_scanner.dart'; export 'src/mdns_scanner/mdns_scanner.dart'; export 'src/models/active_host.dart'; diff --git a/network_tools/lib/src/mdns_scanner/get_srv_list_by_os/srv_list_linux.dart b/network_tools/lib/src/mdns_scanner/get_srv_list_by_os/srv_list_linux.dart index fe82f6b..d4952c4 100644 --- a/network_tools/lib/src/mdns_scanner/get_srv_list_by_os/srv_list_linux.dart +++ b/network_tools/lib/src/mdns_scanner/get_srv_list_by_os/srv_list_linux.dart @@ -1,10 +1,9 @@ import 'dart:collection'; -import 'package:logging/logging.dart'; +import 'package:network_tools/src/netowrk_tools_utils.dart'; import 'package:process_run/shell.dart'; class SrvListLinux { - static final log = Logger("srv_list_linux"); static Future?> getSrvRecordList() async { final HashSet srvList = HashSet(); diff --git a/network_tools/lib/src/mdns_scanner/mdns_scanner.dart b/network_tools/lib/src/mdns_scanner/mdns_scanner.dart index 3f027e7..97e6ef7 100644 --- a/network_tools/lib/src/mdns_scanner/mdns_scanner.dart +++ b/network_tools/lib/src/mdns_scanner/mdns_scanner.dart @@ -1,8 +1,8 @@ -import 'package:logging/logging.dart'; import 'package:multicast_dns/multicast_dns.dart'; import 'package:network_tools/network_tools.dart'; import 'package:network_tools/src/mdns_scanner/get_srv_list_by_os/srv_list.dart'; import 'package:network_tools/src/mdns_scanner/list_of_srv_records.dart'; +import 'package:network_tools/src/netowrk_tools_utils.dart'; import 'package:universal_io/io.dart'; class MdnsScanner { @@ -13,7 +13,6 @@ class MdnsScanner { /// TODO: https://github.com/flutter/flutter/issues/97210 /// TODO: In some cases we resolve this missing functionality using /// TODO: specific os tools. - static final log = Logger('active_host'); static Future> searchMdnsDevices({ bool forceUseOfSavedSrvRecordList = false, diff --git a/network_tools/lib/src/models/active_host.dart b/network_tools/lib/src/models/active_host.dart index 14f1d46..206d112 100644 --- a/network_tools/lib/src/models/active_host.dart +++ b/network_tools/lib/src/models/active_host.dart @@ -1,7 +1,7 @@ import 'package:dart_ping/dart_ping.dart'; -import 'package:logging/logging.dart'; import 'package:network_tools/src/models/mdns_info.dart'; import 'package:network_tools/src/models/open_port.dart'; +import 'package:network_tools/src/netowrk_tools_utils.dart'; import 'package:universal_io/io.dart'; /// ActiveHost which implements comparable @@ -93,8 +93,6 @@ class ActiveHost extends Comparable { Duration? get responseTime => _pingData.response?.time; String get address => internetAddress.address; - final log = Logger('active_host'); - @override int get hashCode => address.hashCode; diff --git a/network_tools/lib/src/netowrk_tools_utils.dart b/network_tools/lib/src/netowrk_tools_utils.dart new file mode 100644 index 0000000..bf3c8ad --- /dev/null +++ b/network_tools/lib/src/netowrk_tools_utils.dart @@ -0,0 +1,3 @@ +import 'package:logging/logging.dart'; + +final log = Logger("network_tools"); From 8f4d42b84c32ada0122e4bd24210a0780ef64840 Mon Sep 17 00:00:00 2001 From: git-elliot Date: Sun, 29 Jan 2023 02:01:34 +0530 Subject: [PATCH 3/3] Removed extra space --- network_tools/lib/src/mdns_scanner/mdns_scanner.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network_tools/lib/src/mdns_scanner/mdns_scanner.dart b/network_tools/lib/src/mdns_scanner/mdns_scanner.dart index 97e6ef7..45404e3 100644 --- a/network_tools/lib/src/mdns_scanner/mdns_scanner.dart +++ b/network_tools/lib/src/mdns_scanner/mdns_scanner.dart @@ -105,7 +105,7 @@ class MdnsScanner { } } catch (e) { log.severe( - 'Error finding ip of mdns record ${foundMdns.ptrResourceRecord.name} srv target ${foundMdns.mdnsSrvTarget} , will add it with ip 0.0.0.0\n$e', + 'Error finding ip of mdns record ${foundMdns.ptrResourceRecord.name} srv target ${foundMdns.mdnsSrvTarget}, will add it with ip 0.0.0.0\n$e', ); final ActiveHost tempHost = ActiveHost( internetAddress: InternetAddress('0.0.0.0'),