Skip to content

Commit

Permalink
Merge pull request #81 from osociety/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
git-elliot authored Jan 28, 2023
2 parents 55efda4 + 8f4d42b commit 199c8ca
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions network_tools/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ analyzer:
- "**/*.pbjson.dart"
- "**/*.gr.dart"
- "**/*.md"
- "example/**"

linter:
rules:
Expand Down
1 change: 0 additions & 1 deletion network_tools/example/host_scan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion network_tools/example/port_scan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 0 additions & 1 deletion network_tools/lib/network_tools.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:collection';

import 'package:network_tools/src/netowrk_tools_utils.dart';
import 'package:process_run/shell.dart';

class SrvListLinux {
Expand All @@ -10,7 +11,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();
}
Expand All @@ -34,7 +35,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 [];
Expand All @@ -58,7 +59,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;
}
Expand All @@ -83,7 +84,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 [];
Expand All @@ -104,7 +105,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;
}
Expand Down
7 changes: 5 additions & 2 deletions network_tools/lib/src/mdns_scanner/mdns_scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 {
Expand All @@ -12,6 +13,7 @@ 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 Future<List<ActiveHost>> searchMdnsDevices({
bool forceUseOfSavedSrvRecordList = false,
}) async {
Expand Down Expand Up @@ -102,8 +104,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,
Expand Down
3 changes: 2 additions & 1 deletion network_tools/lib/src/models/active_host.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:dart_ping/dart_ping.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
Expand Down Expand Up @@ -151,7 +152,7 @@ class ActiveHost extends Comparable<ActiveHost> {
// 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;
Expand Down
3 changes: 3 additions & 0 deletions network_tools/lib/src/netowrk_tools_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:logging/logging.dart';

final log = Logger("network_tools");

0 comments on commit 199c8ca

Please sign in to comment.