Skip to content

Commit

Permalink
Merge branch 'osociety:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 authored Oct 7, 2023
2 parents 7328dc8 + e204fe1 commit d94d0f5
Show file tree
Hide file tree
Showing 55 changed files with 50,690 additions and 759 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "pub" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
26 changes: 19 additions & 7 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
name: Dart

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main", "dev" ]

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

jobs:
build:
runs-on: ${{ matrix.os }}
Expand All @@ -29,7 +31,9 @@ jobs:

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

- name: Run build_runner
run: dart run build_runner build --delete-conflicting-outputs

# Uncomment this step to verify the use of 'dart format' on each commit.
# - name: Verify formatting
Expand All @@ -38,13 +42,21 @@ 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 --coverage="./coverage"

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

- name: Format Coverage
run: dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o ./coverage/coverage.lcov -i ./coverage

- name: Upload Coverage to CodeCov
uses: codecov/codecov-action@v3
with:
token: ${{secrets.CODECOV_TOKEN}}
file: coverage/coverage.lcov
20 changes: 8 additions & 12 deletions .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 All @@ -18,25 +17,24 @@ jobs:
# https://github.com/dart-lang/setup-dart/blob/main/README.md
- uses: dart-lang/[email protected]
# - uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603

- name: Install dependencies
run: dart pub get

- name: Run build_runner
run: dart run build_runner build --delete-conflicting-outputs

- 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
run: dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o ./coverage/coverage.lcov -i ./coverage

- name: Setup Pub Credentials
shell: bash
Expand All @@ -50,15 +48,13 @@ 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
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./network_tools/coverage/coverage.lcov
file: coverage/coverage.lcov

9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,12 @@
.packages
.pub-cache/
.pub/
build/
**/coverage/
**/build/

# Generated sources
*.g.dart
*.config.dart

# Downloaded files
/mac-vendors-export.csv
File renamed without changes.
17 changes: 17 additions & 0 deletions .pubignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# See https://dart.dev/tools/pub/publishing#what-files-are-published

**/example
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
**/coverage/
**/build/
**/test/
**/donation/
*.sh
*.csv

35 changes: 35 additions & 0 deletions network_tools/CHANGELOG.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
# Change Log

## 4.0.1
1. Fixex path problem for dart and flutter sdk

## 4.0.0
### Breaking changes

1. Call configureNetworkTools in your main function


## 3.2.7

1. Removed example folder and added pubignore.
2. Added vendor details but database looks old.
3. More results are added using ARP on Lin/Mac/Win.

## 3.2.6

1. Added mac address support on Desktop (Linux, macOS, and Windows)

## 3.2.5

1. Bug fix for iOS listing all results in HostScanner

## 3.2.4

1. Bug fixes and improvements. Better code coverage reports.

## 3.2.3

1. Upgraded dependencies and improved pub score, moved network_tools_flutter to new repo

## 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
File renamed without changes.
92 changes: 57 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,55 @@
# Network Tools

[![pub package](https://img.shields.io/pub/v/network_tools.svg)](https://pub.dev/packages/network_tools) [![Dart](https://github.com/osociety/network_tools/actions/workflows/dart.yml/badge.svg)](https://github.com/osociety/network_tools/actions/workflows/dart.yml) [![codecov](https://codecov.io/gh/git-elliot/network_tools/branch/main/graph/badge.svg?token=J9G2472GQZ)](https://codecov.io/gh/git-elliot/network_tools)
[![pub package](https://img.shields.io/pub/v/network_tools.svg)](https://pub.dev/packages/network_tools) [![Dart](https://github.com/osociety/network_tools/actions/workflows/dart.yml/badge.svg)](https://github.com/osociety/network_tools/actions/workflows/dart.yml) [![codecov](https://codecov.io/gh/osociety/network_tools/graph/badge.svg?token=J9G2472GQZ)](https://codecov.io/gh/osociety/network_tools)

Network Tools Supported

1. Host Scanner
1. Search all devices on subnet
2. Get mac address of devices on Linux, macOS and Windows.
3. Search devices for a specific port open.

2. Port Scanner
1. Single
1. Single Port scan
2. Range
3. Custom

Partly Work:

1. Mdns Scanner

## Import package in your app
## Network Tools Flutter package

Please check [network_tools_flutter](https://github.com/osociety/network_tools_flutter) package for extensive support to features on different platforms.

## Import package in your app

```dart
import 'package:network_tools/network_tools.dart';
```

## Configure network tools in main function

### For dart native

```dart
Future<void> main() async {
await configureNetworkTools('build', enableDebugging: true);
runApp(const MyApp());
}
```

### For flutter apps

```dart
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// It's necessary to pass correct path to be able to use this library.
final appDocDirectory = await getApplicationDocumentsDirectory();
await configureNetworkTools(appDocDirectory.path, enableDebugging: true);
runApp(const MyApp());
}
```

## Usage
Expand All @@ -30,51 +61,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 All @@ -83,17 +116,6 @@ import 'package:network_tools/network_tools.dart';
2. Run port scan : `dart example/port_scan.dart`
3. Run mdns scan : `dart example/mdns_scan.dart`

## Enable Debugging

Add this code to your `main.dart` file

```dart
Logger.root.level = Level.FINE; //set to finest for detailed log
Logger.root.onRecord.listen((record) {
print(
'${DateFormat.Hms().format(record.time)}: ${record.level.name}: ${record.loggerName}: ${record.message}');
});
```

## Sample App

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ analyzer:
exclude:
- "**/*.g.dart"
- "**/*.freezed.dart"
- "**/*.config.dart"
- "**/*.pb.dart"
- "**/*.pbenum.dart"
- "**/*.pbgrpc.dart"
Expand Down
Loading

0 comments on commit d94d0f5

Please sign in to comment.