Skip to content

Commit

Permalink
Merge pull request #117 from osociety/dev
Browse files Browse the repository at this point in the history
Preparing release for network_tools
  • Loading branch information
git-elliot authored Aug 30, 2023
2 parents 4f99675 + af68c3a commit 3d84bc0
Show file tree
Hide file tree
Showing 21 changed files with 408 additions and 187 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ name: Dart
on:
push:
branches: [ "main" ]
paths: ['network_tools/**']
pull_request:
branches: [ "main", "dev" ]
paths: ['network_tools/**']

concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true

jobs:
build:
Expand Down Expand Up @@ -45,6 +51,4 @@ jobs:
# want to change this to 'flutter test'.
- name: Run tests
run: dart test
working-directory: ./network_tools


working-directory: ./network_tools
71 changes: 71 additions & 0 deletions .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Flutter

on:
push:
branches: [ "main" ]
paths: ['network_tools_flutter/**']
pull_request:
branches: [ "main", "dev-flutter" ]
paths: ['network_tools_flutter/**']

concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- uses: actions/checkout@v3
- name: Setup Java JDK
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: '17'
- name: Flutter action
uses: subosito/[email protected]
with:
channel: stable
- name: Flutter version
run: flutter --version
- name: Cache pubspec dependencies
uses: actions/[email protected]
with:
path: |
${{ env.FLUTTER_HOME }}/.pub-cache
**/.packages
**/.flutter-plugins
**/.flutter-plugin-dependencies
**/.dart_tool/package_config.json
key: build-pubspec-${{ hashFiles('**/pubspec.lock') }}
restore-keys: |
build-pubspec-
- name: Cache build runner
uses: actions/cache@v2
with:
path: |
**/.dart_tool
**/*.g.dart
**/*.mocks.dart
**/*.config.dart
key: build-runner-${{ hashFiles('**/asset_graph.json', '**/*.dart', '**/pubspec.lock', '**/outputs.json') }}
restore-keys: |
build-runner-
- name: Download pub dependencies
run: flutter pub get
working-directory: ./network_tools_flutter
- name: Run analyzer
run: flutter analyze
working-directory: ./network_tools_flutter
- name: Run tests
run: flutter test
working-directory: ./network_tools_flutter
1 change: 0 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:

jobs:
publish:

runs-on: ubuntu-latest

steps:
Expand Down
44 changes: 23 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,51 +30,53 @@ import 'package:network_tools/network_tools.dart';
// 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('.'));
final stream = HostScanner.discover(subnet, firstHostId: 1, lastHostId: 50,
final stream = HostScanner.getAllPingableDevices(subnet, firstHostId: 1, lastHostId: 50,
progressCallback: (progress) {
print('Progress for host discovery : $progress');
});
stream.listen((host) {
//Same host can be emitted multiple times
//Use Set<ActiveHost> instead of List<ActiveHost>
print('Found device: ${host}');
print('Found device: $host');
}, onDone: () {
print('Scan completed');
}); // Don't forget to cancel the stream when not in use.
```

### Port Scanner

```dart
//1. Range
String target = '192.168.1.1';
PortScanner.discover(target, startPort: 1, endPort: 1024,
//1. Range
String target = '192.168.1.1';
PortScanner.scanPortsForSingleDevice(target, startPort: 1, endPort: 1024,
progressCallback: (progress) {
print('Progress for port discovery : $progress');
}).listen((event) {
if (event.isOpen) {
print('Found open port : $event');
}).listen((ActiveHost event) {
if (event.openPorts.isNotEmpty) {
print('Found open ports : ${event.openPorts}');
}
}, onDone: () {
}, onDone: () {
print('Scan completed');
});
//2. Single
bool isOpen = PortScanner.isOpen(target,80);
//3. Custom
PortScanner.customDiscover(target, portList : const [22, 80, 139]);
});
//2. Single
bool isOpen = (await PortScanner.isOpen(target, 80)) == null;
//3. Custom
PortScanner.customDiscover(target, portList: const [22, 80, 139]);
```

### Mdns Scanner

```dart
for (final ActiveHost activeHost in await MdnsScanner.searchMdnsDevices()) {
final MdnsInfo? mdnsInfo = activeHost.mdnsInfo;
print(
'Address: ${activeHost.address}, Port: ${mdnsInfo!.mdnsPort}, ServiceType: ${mdnsInfo.mdnsServiceType}, MdnsName: ${mdnsInfo.getOnlyTheStartOfMdnsName()}',
);
}
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()}
''');
}
```

### Run examples
Expand Down
4 changes: 4 additions & 0 deletions network_tools/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 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
Expand Down
1 change: 0 additions & 1 deletion network_tools/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ analyzer:
missing_required_param: error
missing_return: error
must_be_immutable: error
deprecated_member_use_from_same_package: ignore
exclude:
- "**/*.g.dart"
- "**/*.freezed.dart"
Expand Down
3 changes: 2 additions & 1 deletion network_tools/example/host_scan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void main() {
'${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
Expand All @@ -17,7 +18,7 @@ void main() {

// 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.getAllPingableDevices(
final stream = HostScanner.getAllPingableDevicesAsync(
subnet,
// firstHostId: 1,
// lastHostId: 254,
Expand Down
2 changes: 2 additions & 0 deletions network_tools/lib/network_tools.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// Network tools base library
library network_tools;

//TODO: add dartdocs
Expand All @@ -7,4 +8,5 @@ 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 3d84bc0

Please sign in to comment.