Skip to content

Commit

Permalink
Merge pull request #186 from osociety/dev
Browse files Browse the repository at this point in the history
Dev -> Main
  • Loading branch information
git-elliot authored Mar 14, 2024
2 parents e5bacd8 + 2f7fe5b commit ef88ac2
Show file tree
Hide file tree
Showing 24 changed files with 478 additions and 227 deletions.
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "host scan",
"program": "${workspaceFolder}/example/lib/scan/host_scan.dart",
"request": "launch",
"type": "dart"
},
{
"name": "mdns scan",
"program": "${workspaceFolder}/example/lib/scan/mdns_scan.dart",
"request": "launch",
"type": "dart"
},
{
"name": "port scan",
"program": "${workspaceFolder}/example/lib/scan/port_scan.dart",
"request": "launch",
"type": "dart"
},
]
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## 4.0.5
1. Added hostIds list parameter to restrict scan to only these ids.

## 4.0.4
1. Bug fix for sync runs when async flag is true

Expand Down
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ analyzer:
- "**/*.pbjson.dart"
- "**/*.gr.dart"
- "**/*.md"
- "example/**"

linter:
rules:
Expand Down
3 changes: 3 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
void main() {
// ignore: avoid_print
print("Run host scan : 'dart example/lib/scan/host_scan.dart'");
// ignore: avoid_print
print("Run port scan : 'dart example/lib/scan/port_scan.dart'");
// ignore: avoid_print
print("Run mdns scan : 'dart example/lib/scan/mdns_scan.dart'");
}
8 changes: 4 additions & 4 deletions example/lib/scan/host_scan.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:logging/logging.dart';
import 'package:network_tools/network_tools.dart';

import '../example_utils.dart';

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

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

final interface = await NetInterface.localInterface();
final netId = interface?.networkId;
Expand All @@ -20,7 +20,7 @@ Future<void> main() async {

// 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 stream = HostScanner.getAllPingableDevicesAsync(
final stream = HostScannerService.instance.getAllPingableDevicesAsync(
subnet,
// firstHostId: 1,
// lastHostId: 254,
Expand All @@ -30,7 +30,7 @@ Future<void> main() async {
);

stream.listen(
(final host) async {
(host) async {
//Same host can be emitted multiple times
//Use Set<ActiveHost> instead of List<ActiveHost>
examplesLog.fine('Found device: ${await host.toStringFull()}');
Expand Down
3 changes: 2 additions & 1 deletion example/lib/scan/mdns_scan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import '../example_utils.dart';
Future<void> main() async {
enableExampleLogging();
await configureNetworkTools('build');
for (final ActiveHost activeHost in await MdnsScanner.searchMdnsDevices()) {
for (final ActiveHost activeHost
in await MdnsScannerService.instance.searchMdnsDevices()) {
final MdnsInfo? mdnsInfo = await activeHost.mdnsInfo;
examplesLog.fine(
'Address: ${activeHost.address}, Port: ${mdnsInfo!.mdnsPort}, ServiceType: ${mdnsInfo.mdnsServiceType}, MdnsName: ${mdnsInfo.getOnlyTheStartOfMdnsName()}, Mdns Device Name: ${mdnsInfo.mdnsSrvTarget}\n',
Expand Down
15 changes: 8 additions & 7 deletions example/lib/scan/port_scan.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:logging/logging.dart';
import 'package:network_tools/network_tools.dart';

import '../example_utils.dart';

Future<void> main() async {
Expand All @@ -18,7 +18,7 @@ Future<void> main() async {
// [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 = HostScanner.scanDevicesForSinglePort(
final stream2 = HostScannerService.instance.scanDevicesForSinglePort(
subnet,
53,
progressCallback: (progress) {
Expand All @@ -27,9 +27,9 @@ Future<void> main() async {
);

stream2.listen(
(activeHost) {
examplesLog.fine(
'[scanDevicesForSinglePort]: Found device : ${activeHost.toString()}');
(ActiveHost activeHost) {
examplesLog
.fine('[scanDevicesForSinglePort]: Found device : $activeHost');
final OpenPort deviceWithOpenPort = activeHost.openPorts[0];
if (deviceWithOpenPort.isOpen) {
examplesLog.fine(
Expand All @@ -49,7 +49,7 @@ Future<void> main() async {
examplesLog.fine("Target is $target");
}

PortScanner.scanPortsForSingleDevice(
PortScannerService.instance.scanPortsForSingleDevice(
target,
// Scan will start from this port.
// startPort: 1,
Expand All @@ -63,7 +63,8 @@ Future<void> main() async {

if (deviceWithOpenPort.isOpen) {
examplesLog.fine(
'Found open port: ${deviceWithOpenPort.port} on device $target');
'Found open port: ${deviceWithOpenPort.port} on device $target',
);
}
},
onDone: () {
Expand Down
12 changes: 0 additions & 12 deletions lib/injectable.dart

This file was deleted.

45 changes: 6 additions & 39 deletions lib/network_tools.dart
Original file line number Diff line number Diff line change
@@ -1,54 +1,21 @@
/// Network tools base library
library network_tools;

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/configure_dart_native.dart';
export 'src/device_info/net_interface.dart';
export 'src/device_info/vendor_table.dart';
export 'src/host_scanner.dart';
export 'src/mdns_scanner/list_of_srv_records.dart';
export 'src/mdns_scanner/mdns_scanner.dart';
export 'src/models/active_host.dart';
export 'src/models/arp_data.dart';
export 'src/models/callbacks.dart';
export 'src/models/mdns_info.dart';
export 'src/models/open_port.dart';
export 'src/models/sendable_active_host.dart';
export 'src/models/vendor.dart';
export 'src/port_scanner.dart';

final _getIt = GetIt.instance;
late bool _enableDebugging;

late String _dbDirectory;
export 'src/services/host_scanner_service.dart';
export 'src/services/mdns_scanner_service.dart';
export 'src/services/port_scanner_service.dart';

String get dbDirectory => _dbDirectory;
bool get enableDebugging => _enableDebugging;
late bool enableDebugging;

Future<void> configureNetworkTools(
String dbDirectory, {
bool enableDebugging = false,
}) async {
_enableDebugging = enableDebugging;
_dbDirectory = dbDirectory;
if (enableDebugging) {
Logger.root.level = Level.FINE;
Logger.root.onRecord.listen((record) {
if (record.loggerName == log.name) {
// ignore: avoid_print
print(
'${record.time.toLocal()}: ${record.level.name}: ${record.loggerName}: ${record.message}',
);
}
});
}
configureDependencies();
final arpService = await _getIt<ARPService>().open();
await arpService.buildTable();
await VendorTable.createVendorTableMap();
}
late String dbDirectory;
38 changes: 38 additions & 0 deletions lib/src/configure_dart_native.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:logging/logging.dart';
import 'package:network_tools/network_tools.dart' as pacakges_page;
import 'package:network_tools/src/network_tools_utils.dart';
import 'package:network_tools/src/services/arp_service.dart';
import 'package:network_tools/src/services/impls/arp_service_sembast_impl.dart';
import 'package:network_tools/src/services/impls/host_scanner_service_impl.dart';
import 'package:network_tools/src/services/impls/mdns_scanner_service_impl.dart';
import 'package:network_tools/src/services/impls/port_scanner_service_impl.dart';

Future<void> configureNetworkTools(
String dbDirectory, {
bool enableDebugging = false,
}) async {
pacakges_page.enableDebugging = enableDebugging;
pacakges_page.dbDirectory = dbDirectory;

if (pacakges_page.enableDebugging) {
Logger.root.level = Level.FINE;
Logger.root.onRecord.listen((record) {
if (record.loggerName == log.name) {
// ignore: avoid_print
print(
'${record.time.toLocal()}: ${record.level.name}: ${record.loggerName}: ${record.message}',
);
}
});
}

/// Setting dart native classes implementations
ARPServiceSembastImpl();
HostScannerServiceImpl();
PortScannerServiceImpl();
MdnsScannerServiceImpl();

final arpService = await ARPService.instance.open();
await arpService.buildTable();
await pacakges_page.VendorTable.createVendorTableMap();
}
7 changes: 5 additions & 2 deletions lib/src/device_info/vendor_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ class VendorTable {
if (arpData.notNullMacAddress) {
await createVendorTableMap();
final pattern = arpData.macAddress.contains(':') ? ':' : '-';
return _vendorTableMap[
arpData.macAddress.split(pattern).sublist(0, 3).join()] as Vendor?;
return _vendorTableMap[arpData.macAddress
.split(pattern)
.sublist(0, 3)
.join()
.toUpperCase()] as Vendor?;
}
}
return null;
Expand Down
55 changes: 28 additions & 27 deletions lib/src/mdns_scanner/list_of_srv_records.dart
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
/// Service record list that is including the protocol, mostly _tcp, _udp may
/// not work
List<String> tcpSrvRecordsList = [
'_autodiscover._tcp',
'_http._tcp', // "domain": "bosch_shc", "name": "bosch shc*"
'_http-alt._tcp',
'_googlecast._tcp', // Is there a ChromeCast-capable device in this network "domain": "cast"
'_androidtvremote2._tcp',
'_smartview._tcp', // Samsung tv's
'_spotify-connect._tcp', // "domain": "spotify"
'_nanoleafapi._tcp', // "domain": "nanoleaf"
'_nanoleafms._tcp', // "domain": "nanoleaf"
'_esphomelib._tcp', // [ { "domain": "esphome" }, { "domain": "zha", "name": "tube*" } ]
'_ewelink._tcp', // Ewelink devices
'_hue._tcp', // "domain": "hue"
'_mqtt._tcp',
'_hap._tcp', // [ { "domain": "homekit_controller" }, { "domain": "zwave_me", "name": "*z.wave-me*" } ]
'_homekit._tcp', // "domain": "homekit"
'_hscp._tcp', // "domain": "apple_tv"
'_appletv-v2._tcp', // "domain": "apple_tv"
'_airplay._tcp', // Any Apple AirPlay-capable video displays here_ipps // [ { "domain": "apple_tv", "properties": { "model": "appletv*" } }, { "domain": "apple_tv", "properties": { "model": "audioaccessory*" } }, { "domain": "apple_tv", "properties": { "am": "airport*" } }, { "domain": "samsungtv", "properties": { "manufacturer": "samsung*" } } ]
'_raop._tcp', // Any Apple AirPlay-capable audio devices [ { "domain": "apple_tv", "properties": { "am": "appletv*" } }, { "domain": "apple_tv", "properties": { "am": "audioaccessory*" } }, { "domain": "apple_tv", "properties": { "am": "airport*" } } ],
'_airport._tcp', // Any Apple AirPort WiFi APs // "domain": "apple_tv"
'_touch-able._tcp', // "domain": "apple_tv"
'_mediaremotetv._tcp', // "domain": "apple_tv"
'_uscan._tcp', // Any HP-compatible network scanners
'_uscans._tcp', // Any SSL/TLS-capable HP-compatible network scanners
'_privet._tcp', // Any Google CloudPrint-capable printers or print services
'_http-alt._tcp',
'_scanner._tcp', // Are there any Bonjour-capable scanners
'_home-assistant._tcp',
'_pdl-datastream._tcp', // Any HP JetDirect-style network printers
'_ipp._tcp', // Are there any printers using the IPP protocol // "domain": "ipp"
'_ipps._tcp', // Any SSL/TLS capable IPP printers // "domain": "ipp"
'_http._tcp', // "domain": "bosch_shc", "name": "bosch shc*"
'_ldap._tcp',
'_gc._tcp',
'_kerberos._tcp',
'_kpasswd._tcp',
'_airplay._tcp', // Any Apple AirPlay-capable video displays here_ipps // [ { "domain": "apple_tv", "properties": { "model": "appletv*" } }, { "domain": "apple_tv", "properties": { "model": "audioaccessory*" } }, { "domain": "apple_tv", "properties": { "am": "airport*" } }, { "domain": "samsungtv", "properties": { "manufacturer": "samsung*" } } ]
'_raop._tcp', // Any Apple AirPlay-capable audio devices [ { "domain": "apple_tv", "properties": { "am": "appletv*" } }, { "domain": "apple_tv", "properties": { "am": "audioaccessory*" } }, { "domain": "apple_tv", "properties": { "am": "airport*" } } ],
'_ippusb._tcp', // Are there any shared printers that are using the IPP-over-USB protocol, i.e. USB-connected printers shared by a Mac
'_printer._tcp', // Any kinds of shared printers at all "domain": "brother", "name": "brother*"
'_ptp._tcp', // Any devices supporting the Picture Transfer Protocol over this network
'_googlecast._tcp', // Is there a ChromeCast-capable device in this network "domain": "cast"
'_airport._tcp', // Any Apple AirPort WiFi APs // "domain": "apple_tv"
'_esphomelib._tcp', // [ { "domain": "esphome" }, { "domain": "zha", "name": "tube*" } ]
'_mqtt._tcp',
'_autodiscover._tcp',
'_kpasswd._tcp',
'_ldap._tcp',
'_gc._tcp',
'_kerberos._tcp',
'_sip._tcp',
'_minecraft._tcp',
'_Volumio._tcp', // "domain": "volumio"
'_api._tcp', // [ { "domain": "baf", "properties": { "model": "haiku*" } }, { "domain": "baf", "properties": { "model": "i6*" } } ]
'_appletv-v2._tcp', // "domain": "apple_tv"
'_axis-video._tcp', // [ { "domain": "axis", "properties": { "macaddress": "00408c*" } }, { "domain": "axis", "properties": { "macaddress": "accc8e*" } }, { "domain": "axis", "properties": { "macaddress": "b8a44f*" } }, { "domain": "doorbird", "properties": { "macaddress": "1ccae3*"} } ],
'_bond._tcp', // "domain": "bond"
'_companion-link._tcp', // "domain": "apple_tv"
Expand All @@ -40,17 +51,10 @@ List<String> tcpSrvRecordsList = [
'_elg._tcp', // "domain": "elgato"
'_enphase-envoy._tcp', // "domain": "enphase_envoy"
'_fbx-api._tcp', // "domain": "freebox"
'_hap._tcp', // [ { "domain": "homekit_controller" }, { "domain": "zwave_me", "name": "*z.wave-me*" } ]
'_homekit._tcp', // "domain": "homekit"
'_hscp._tcp', // "domain": "apple_tv"
'_hue._tcp', // "domain": "hue"
'_hwenergy._tcp', // "domain": "homewizard",
'_kizbox._tcp', // "domain": "overkiz", "name": "gateway*"
'_leap._tcp', // "domain": "lutron_caseta"
'_lookin._tcp', // "domain": "lookin"
'_mediaremotetv._tcp', // "domain": "apple_tv"
'_nanoleafapi._tcp', // "domain": "nanoleaf"
'_nanoleafms._tcp', // "domain": "nanoleaf"
'_nut._tcp', // "domain": "nut"
'_octoprint._tcp', // "domain": "octoprint"
'_plexmediasvr._tcp', // "domain": "plex"
Expand All @@ -59,20 +63,16 @@ List<String> tcpSrvRecordsList = [
'_sideplay._tcp', // { "domain": "ecobee", "properties": { "mdl": "eb-*" } }, { "domain": "ecobee", "properties": { "mdl": "ecobee*" } }
'_sonos._tcp', // "domain": "sonos"
'_soundtouch._tcp', // "domain": "soundtouch"
'_spotify-connect', // "domain": "spotify"
'_ssh._tcp', // { "domain": "smappee", "name": "smappee1*" }, { "domain": "smappee", "name": "smappee2*" }, { "domain": "smappee", "name": "smappee50*" }
'_system-bridge._tcp', // "domain": "system_bridge"
'_touch-able._tcp', // "domain": "apple_tv"
'_viziocast._tcp', // "domain": "vizio"
'_wled._tcp', // "domain": "wled"
'_xbmc-jsonrpc-h._tcp', // "domain": "kodi"
'_home-assistant._tcp',
'_zigate-zigbee-gateway._tcp', // "domain": "zha", "name": "*zigate*"
'_zwave-js-server._tcp', // "domain": "zwave_js"
'_axis-video._tcp', // "properties": { "macaddress": "00408c*" } "properties": { "macaddress": "accc8e*" } "properties": { "macaddress": "b8a44f*" }
'_androidtvremote2._tcp',
'_ewelink._tcp', // Ewelink devices
'_nvstream_dbd._tcp',
'_smartview._tcp', // Samsung tv's
];

List<String> udpSrvRecordsList = [
Expand All @@ -81,4 +81,5 @@ List<String> udpSrvRecordsList = [
'_miio._udp', // [ { "domain": "xiaomi_aqara" }, { "domain": "xiaomi_miio" }, { "domain": "yeelight", "name": "yeelink-*" } ]
'_sleep-proxy._udp', // "domain": "apple_tv"
'_system-bridge._udp',
'_kdeconnect._udp',
];
Loading

0 comments on commit ef88ac2

Please sign in to comment.