Skip to content

Commit

Permalink
Merge pull request #120 from osociety/flutter_port_scan
Browse files Browse the repository at this point in the history
Flutter package is moved to new repo
  • Loading branch information
git-elliot authored Aug 31, 2023
2 parents f0b7957 + 75421f0 commit 07a4b69
Show file tree
Hide file tree
Showing 36 changed files with 1,599 additions and 261 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ name: Dart
on:
push:
branches: [ "main" ]
paths: ['network_tools/**']
pull_request:
branches: [ "main", "dev" ]
paths: ['network_tools/**']

concurrency:
group: ${{ github.head_ref || github.run_id }}
Expand All @@ -35,7 +33,6 @@ jobs:

- name: Install dependencies
run: dart pub get
working-directory: ./network_tools

# Uncomment this step to verify the use of 'dart format' on each commit.
# - name: Verify formatting
Expand All @@ -44,11 +41,9 @@ jobs:
# Consider passing '--fatal-infos' for slightly stricter analysis.
- name: Analyze project source
run: dart analyze --fatal-infos
working-directory: ./network_tools

# Your project will need to have tests in test/ and a dependency on
# package:test for this step to succeed. Note that Flutter projects will
# want to change this to 'flutter test'.
- name: Run tests
run: dart test
working-directory: ./network_tools
run: dart test
12 changes: 3 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,21 @@ jobs:
# https://github.com/dart-lang/setup-dart/blob/main/README.md
- uses: dart-lang/setup-dart@v1.4
# - uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603

- name: Install dependencies
run: dart pub get

- name: Analyze project source
run: dart analyze --fatal-infos
working-directory: ./network_tools

- name: Run tests
run: dart test --coverage="coverage"
working-directory: ./network_tools

- name: Install dependencies
run: dart pub get
working-directory: ./network_tools

- name: Install coverage tools
run: dart pub global activate coverage

- name: Format Coverage
run: $HOME/.pub-cache/bin/format_coverage --lcov --in=coverage --out=coverage/coverage.lcov --report-on=lib
working-directory: ./network_tools

- name: Setup Pub Credentials
shell: bash
Expand All @@ -49,11 +45,9 @@ jobs:
- name: Check Publish Warnings
run: dart pub publish --dry-run
working-directory: ./network_tools

- name: Publish Package
run: dart pub publish -f
working-directory: ./network_tools

- name: Upload Coverage to CodeCov
uses: codecov/codecov-action@v3
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
.packages
.pub-cache/
.pub/
build/
**/coverage/
**/build/

2 changes: 1 addition & 1 deletion network_tools_flutter/.metadata → .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file should be version controlled and should not be manually edited.

version:
revision: f1875d570e39de09040c8f79aa13cc56baab8db1
revision: 02c026b03cd31dd3f867e5faeb7e104cce174c5f
channel: stable

project_type: package
101 changes: 101 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Change Log

## 3.2.2

1. Supporting changes for network_tools_flutter

## 3.2.1

1. Now GHA runs tests against 3 platforms windows, ubuntu, macos
2. Code coverage is fixed so that it's visible in codecov portal.

## 3.2.0

1. getAllPingableDevicesAsync runs inside isolate to find all devices in a network.
2. Bug fixes and improvements

## 3.1.0

Web Support and bug fixes for mDns devices giving error in getting IP

## 3.0.0+3

Refactoring for field names

## 3.0.0+2

This release is only meant to test Github Actions for Dart Package publishing. It's same as v3.0.0. Nothing changed.

## 3.0.0+1

This release is only meant to test Github Actions for Dart Package publishing. It's same as v3.0.0. Nothing changed.

## 3.0.0

**Breaking change** Change most of the methods names

* HostScanner.discover to HostScanner.getAllPingableDevices
* HostScanner.discoverPort to HostScanner.scanDevicesForSinglePort
* PortScanner.discover to PortScanner.scanPortsForSingleDevice

Ip field in ActiveHost is now InternetAddress type instead of string which improve handling of IPv6.

ActiveHost now contains host name of the address if exist.

Better naming of methods

Bug fixes and improvements

## 2.1.0

Added partly support for searching mdns devices.

## 2.0.0

**Breaking change** Bump minimum dart version to 2.17.0.

Updated dart_ping package version to 7.0.1.

Updated test package version to 1.21.4.

## 1.0.8

Fixes

Add logs using logging package #13.

Even more points in pub.dev page #20.

## 1.0.7

Fixed

Saving the response time from each device #9.

Example crash on Windows #14.

Bump package version #15.

## 0.0.6

Resolved issue #9 and #10.

## 0.0.5

Resolved issue #1.

## 0.0.4

Single and Custom Port Scan added.

## 0.0.3

Subnet and Port range added.

## 0.0.2

Added example and followed pub conventions.

## 0.0.1

PortScanner and HostScanner.
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2021, Elliot Alderson
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 changes: 35 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Defines a default set of lint rules enforced for
# projects at Google. For details and rationale,
# see https://github.com/dart-lang/pedantic#enabled-lints.
#include: package:pedantic/analysis_options.yaml

# lint analysis
include: package:lint/analysis_options.yaml


analyzer:
errors:
missing_required_param: error
missing_return: error
must_be_immutable: error
exclude:
- "**/*.g.dart"
- "**/*.freezed.dart"
- "**/*.pb.dart"
- "**/*.pbenum.dart"
- "**/*.pbgrpc.dart"
- "**/*.pbjson.dart"
- "**/*.gr.dart"
- "**/*.md"
- "example/**"

linter:
rules:
# Use parameter order as in json response
always_put_required_named_parameters_first: true

avoid_classes_with_only_static_members: false

sort_constructors_first: true

avoid_relative_lib_imports: false
40 changes: 40 additions & 0 deletions example/host_scan.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:intl/intl.dart';
import 'package:logging/logging.dart';
import 'package:network_tools/network_tools.dart';

void main() {
Logger.root.level = Level.FINE;
Logger.root.onRecord.listen((record) {
print(
'${DateFormat.Hms().format(record.time)}: ${record.level.name}: ${record.loggerName}: ${record.message}',
);
});
final log = Logger("host_scan_example");

const String address = '192.168.1.1';
// or You can also get address using network_info_plus package
// final String? address = await (NetworkInfo().getWifiIP());
final String subnet = address.substring(0, address.lastIndexOf('.'));

// 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(
subnet,
// firstHostId: 1,
// lastHostId: 254,
progressCallback: (progress) {
log.finer('Progress for host discovery : $progress');
},
);

stream.listen(
(ActiveHost host) async {
//Same host can be emitted multiple times
//Use Set<ActiveHost> instead of List<ActiveHost>
log.fine('Found device: ${await host.toStringFull()}');
},
onDone: () {
log.fine('Scan completed');
},
); // Don't forget to cancel the stream when not in use.
}
5 changes: 5 additions & 0 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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'");
}
10 changes: 10 additions & 0 deletions example/mdns_scan.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:network_tools/network_tools.dart';

Future<void> main() async {
for (final ActiveHost activeHost in await MdnsScanner.searchMdnsDevices()) {
final MdnsInfo? mdnsInfo = await activeHost.mdnsInfo;
print(
'Address: ${activeHost.address}, Port: ${mdnsInfo!.mdnsPort}, ServiceType: ${mdnsInfo.mdnsServiceType}, MdnsName: ${mdnsInfo.getOnlyTheStartOfMdnsName()}, Mdns Device Name: ${mdnsInfo.mdnsSrvTarget}',
);
}
}
66 changes: 66 additions & 0 deletions example/port_scan.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'package:intl/intl.dart';
import 'package:logging/logging.dart';
import 'package:network_tools/network_tools.dart';

void main() {
Logger.root.level = Level.FINE;
Logger.root.onRecord.listen((record) {
print(
'${DateFormat.Hms().format(record.time)}: ${record.level.name}: ${record.loggerName}: ${record.message}',
);
});

const String address = '192.168.1.1';
// or You can also get address using network_info_plus package
// final String? address = await (NetworkInfo().getWifiIP());
final String subnet = address.substring(0, address.lastIndexOf('.'));

// [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(
subnet,
53,
// firstHostId: 1,
// lastHostId: 254,
progressCallback: (progress) {
log.finer('Progress for port discovery on host : $progress');
},
);

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

const String target = '192.168.1.1';
PortScanner.scanPortsForSingleDevice(
target,
// Scan will start from this port.
// startPort: 1,
endPort: 9400,
progressCallback: (progress) {
log.finer('Progress for port discovery : $progress');
},
).listen(
(activeHost) {
final OpenPort deviceWithOpenPort = activeHost.openPort[0];

if (deviceWithOpenPort.isOpen) {
log.fine('Found open port: ${deviceWithOpenPort.port}');
}
},
onDone: () {
log.fine('Port Scan from 1 to 9400 completed');
},
);
}
12 changes: 12 additions & 0 deletions lib/network_tools.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// Network tools base library
library network_tools;

//TODO: add dartdocs
export 'src/host_scanner.dart';
export 'src/mdns_scanner/mdns_scanner.dart';
export 'src/models/active_host.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/port_scanner.dart';
Loading

0 comments on commit 07a4b69

Please sign in to comment.