Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

dart_ping_ios/.flutter-plugins-dependencies
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ In order to provide compatibility on iOS (via Flutter Method Channels) while ret
[dart_ping](dart_ping) is the main package which supports Windows, Mac, Linux, and Android natively without additional binaries

[dart_ping_ios](dart_ping_ios) is a plugin which adds cocoa dependencies to support ping on iOS systems. Using this plugin requires the Flutter SDK to be added to your dart project.

### Windows Compatibility

When using this package with Flutter for Windows, release builds [may not work as intended](https://github.com/point-source/dart_ping/issues/16). This is due to a [known issue](https://github.com/dart-lang/sdk/issues/39945) with the Flutter framework on windows. There is [a workaround described here.](https://github.com/dart-lang/sdk/issues/39945#issuecomment-870428151)
14 changes: 14 additions & 0 deletions dart_ping/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 8.0.1

- Fix windows timeout flag (Issue #37)

## 8.0.0

- Use named capture groups for regex parsing
- Return false instead of throwing exception when stop() is called prematurely

## 7.0.2

- Remove windows compatibility warning. Issue #27 / fixed upstream
- Add repository link to pubspec / pub.dev

## 7.0.1

- Add documentation note about apple app sandbox in release mode
Expand Down
17 changes: 10 additions & 7 deletions dart_ping/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ void main() async {
}
```

Instead of listening to a stream, you can perform a single ping and immediately return the result like so:

```dart
final result = await Ping('google.com', count: 1).stream.first;
```

To use dart_ping on iOS, add the [dart_ping_ios](https://pub.dev/packages/dart_ping_ios) package as a dependency and register the iOS plugin before initializing Ping. For more detailed docs, see the [dart_ping_ios](https://pub.dev/packages/dart_ping_ios) package. Note that the iOS plugin requires the flutter sdk. (this is why it is not integrated into dart_ping directly)

```dart
Expand Down Expand Up @@ -49,9 +55,9 @@ To override the parser to support an alternative OS language
```dart
final parser = PingParser(
responseStr: RegExp(r'Resposta de'),
responseRgx: RegExp(r'de (.*): bytes=(\d+) tempo=(\d+)ms TTL=(\d+)'),
responseRgx: RegExp(r'de (?<ip>.*): bytes=(?:\d+) tempo=(?<time>\d+)ms TTL=(?<ttl>\d+)'),
summaryStr: RegExp(r'Perdidos'),
summaryRgx: RegExp(r'Enviados = (\d+), Recebidos = (\d+), Perdidos = (\d+)'),
summaryRgx: RegExp(r'Enviados = (?<tx>\d+), Recebidos = (?<rx>\d+), Perdidos = (?:\d+)'),
timeoutStr: RegExp(r'host unreachable'),
unknownHostStr: RegExp(r'A solicitação ping não pôde encontrar o host'));

Expand All @@ -63,20 +69,17 @@ To override the character encoding to ignore non-utf characters:
```dart
final ping = Ping('google.com', encoding: Utf8Codec(allowMalformed: true));
```

### macOS Release Build with App Sandbox
When building in release mode with [app sandbox](https://developer.apple.com/documentation/security) enabled, you must ensure you add the following entitlements to the Release.entitlements file in your macos folder:

```
```xml
<key>com.apple.security.network.server</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
```

### Windows Compatibility

When using this package with Flutter for Windows, release builds [may not work as intended](https://github.com/point-source/dart_ping/issues/16). This is due to a [known issue](https://github.com/dart-lang/sdk/issues/39945) with the Flutter framework on windows. There is [a workaround described here.](https://github.com/dart-lang/sdk/issues/39945#issuecomment-870428151)

## Features and bugs

Please file feature requests and bugs at the [issue tracker][tracker].
Expand Down
23 changes: 10 additions & 13 deletions dart_ping/lib/src/models/ping_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,15 @@ class PingParser {
RegExp? errorStr;

// ignore: long-method
StreamTransformer<String, PingData> get responseParser =>
StreamTransformer<String, PingData>.fromHandlers(
StreamTransformer<String, PingData> get responseParser => StreamTransformer<String, PingData>.fromHandlers(
handleData: (data, sink) {
// Timeout
if (sequenceRgx != null && data.contains(timeoutStr)) {
final match = sequenceRgx!.firstMatch(data);
if (match == null) {
return;
}
var seq = match.group(1);
var seq = match.namedGroup('seq');
sink.add(
PingData(
response: PingResponse(
Expand All @@ -71,13 +70,13 @@ class PingParser {
if (match == null) {
return;
}
var seq = match.group(2);
var ttl = match.group(3);
var time = match.group(4);
var seq = match.groupNames.contains('seq') ? match.namedGroup('seq') : null;
var ttl = match.namedGroup('ttl');
var time = match.namedGroup('time');
sink.add(
PingData(
response: PingResponse(
ip: match.group(1),
ip: match.namedGroup('ip'),
seq: seq?.isEmpty ?? true ? null : int.parse(seq!),
ttl: ttl == null ? null : int.parse(ttl),
time: time == null
Expand All @@ -93,11 +92,11 @@ class PingParser {
// Summary
if (data.contains(summaryStr)) {
final match = summaryRgx.firstMatch(data);
var tx = match?.group(1);
var rx = match?.group(2);
var tx = match?.namedGroup('tx');
var rx = match?.namedGroup('rx');
String? time;
if ((match?.groupCount ?? 0) > 2) {
time = match?.group(3);
time = match?.namedGroup('time');
}
if (tx == null || rx == null) {
return;
Expand All @@ -107,9 +106,7 @@ class PingParser {
summary: PingSummary(
transmitted: int.parse(tx),
received: int.parse(rx),
time: time == null
? null
: Duration(milliseconds: int.parse(time)),
time: time == null ? null : Duration(milliseconds: int.parse(time)),
),
),
);
Expand Down
4 changes: 0 additions & 4 deletions dart_ping/lib/src/ping/base_ping.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ abstract class BasePing {
}

Future<bool> stop() async {
// ignore: unnecessary_null_comparison
if (_process == null) {
throw Exception('Cannot kill a process that has not yet been started');
}
if (_process?.kill(ProcessSignal.sigint) ?? false) {
await _controller.done;

Expand Down
15 changes: 5 additions & 10 deletions dart_ping/lib/src/ping/linux_ping.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ class PingLinux extends BasePing implements Ping {

static PingParser get _parser => PingParser(
responseStr: RegExp(r'bytes from'),
responseRgx:
RegExp(r'from (.*): icmp_seq=(\d+) ttl=(\d+) time=((\d+).?(\d+))'),
sequenceRgx: RegExp(r'icmp_seq=(\d+)'),
responseRgx: RegExp(r'from (?<ip>.*): icmp_seq=(?<seq>\d+) ttl=(?<ttl>\d+) time=(?<time>(\d+).?(\d+))'),
sequenceRgx: RegExp(r'icmp_seq=(?<seq>\d+)'),
summaryStr: RegExp(r'packet loss'),
summaryRgx:
RegExp(r'(\d+) packets transmitted, (\d+) received,.*time (\d+)ms'),
summaryRgx: RegExp(r'(?<tx>\d+) packets transmitted, (?<rx>\d+) received,.*time (?<time>\d+)ms'),
timeoutStr: RegExp(r'no answer yet'),
unknownHostStr:
RegExp(r'unknown host|service not known|failure in name'),
unknownHostStr: RegExp(r'unknown host|service not known|failure in name'),
);

@override
Expand All @@ -55,8 +52,6 @@ class PingLinux extends BasePing implements Ping {

@override
Exception? throwExit(int exitCode) {
return exitCode > 1
? Exception('Ping process exited with code: $exitCode')
: null;
return exitCode > 1 ? Exception('Ping process exited with code: $exitCode') : null;
}
}
12 changes: 7 additions & 5 deletions dart_ping/lib/src/ping/mac_ping.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ class PingMac extends BasePing implements Ping {

static PingParser get _parser => PingParser(
responseStr: RegExp(r'bytes from'),
responseRgx:
RegExp(r'from (.*): icmp_seq=(\d+) ttl=(\d+) time=((\d+).?(\d+))'),
sequenceRgx: RegExp(r'icmp_seq (\d+)'),
responseRgx: RegExp(
r'from (?<ip>.*): icmp_seq=(?<seq>\d+) ttl=(?<ttl>\d+) time=(?<time>(\d+).?(\d+))',
),
sequenceRgx: RegExp(r'icmp_seq (?<seq>\d+)'),
summaryStr: RegExp(r'packet loss'),
summaryRgx:
RegExp(r'(\d+) packets transmitted, (\d+) packets received'),
summaryRgx: RegExp(
r'(?<tx>\d+) packets transmitted, (?<rx>\d+) packets received',
),
timeoutStr: RegExp(r'Request timeout'),
unknownHostStr: RegExp(r'Unknown host'),
);
Expand Down
9 changes: 6 additions & 3 deletions dart_ping/lib/src/ping/windows_ping.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ class PingWindows extends BasePing implements Ping {

static PingParser get _parser => PingParser(
responseStr: RegExp(r'Reply from'),
responseRgx: RegExp(r'from (.*): bytes=\d+() time=(\d+)ms TTL=(\d+)'),
responseRgx: RegExp(
r'from (?<ip>.*): bytes=(?:\d+) time(?:=|<)(?<time>\d+)ms TTL=(?<ttl>\d+)',
),
summaryStr: RegExp(r'Lost'),
summaryRgx: RegExp(r'Sent = (\d+), Received = (\d+), Lost = (\d+)'),
summaryRgx:
RegExp(r'Sent = (?<tx>\d+), Received = (?<rx>\d+), Lost = (?:\d+)'),
timeoutStr: RegExp(r'host unreachable|timed out'),
unknownHostStr: RegExp(r'could not find host'),
errorStr: RegExp(r'transmit failed'),
Expand All @@ -40,7 +43,7 @@ class PingWindows extends BasePing implements Ping {
@override
List<String> get params {
if (ipv6) throw UnimplementedError('IPv6 not implemented for windows');
var params = ['-w', timeout.toString(), '-i', ttl.toString()];
var params = ['-w', (timeout * 1000).toString(), '-i', ttl.toString()];
if (ipv6) {
params.add('-6');
} else {
Expand Down
5 changes: 3 additions & 2 deletions dart_ping/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: dart_ping
description: Multi-platform network ping utility for native desktop and android applications.
version: 7.0.1
version: 8.0.1
homepage: https://github.com/point-source/dart_ping
repository: https://github.com/point-source/dart_ping

environment:
sdk: ">=2.17.0 <3.0.0"
Expand All @@ -11,6 +12,6 @@ dependencies:
collection: ^1.16.0

dev_dependencies:
dart_code_metrics: ^4.8.1
dart_code_metrics: ^5.4.0
lints: ^2.0.0
test: ^1.14.4
2 changes: 1 addition & 1 deletion dart_ping/test/misuse.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ void main() {
group('Misuse: ', () {
test('Termination before starting', () async {
var ping = Ping('1.1.1.1', count: 5);
expect(ping.stop(), throwsException);
expect(await ping.stop(), isFalse);
});
});
}
2 changes: 1 addition & 1 deletion dart_ping/test/ping.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void main() {
var ping = Ping('201.202.203.204', count: 2, ttl: 1);
var data = await ping.stream.last;
expect(data, isA<PingData>());
expect(data.summary?.errors.toString(), contains('NoReply'));
expect(data.summary?.errors.toString(), contains('requestTimedOut'));
});
});
}
2 changes: 1 addition & 1 deletion dart_ping_ios/.flutter-plugins
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This is a generated file; do not edit or check into version control.
flutter_icmp_ping=/Users/andrew/.pub-cache/hosted/pub.dartlang.org/flutter_icmp_ping-3.1.0/
flutter_icmp_ping=/Users/andrew/.pub-cache/hosted/pub.dartlang.org/flutter_icmp_ping-3.1.1/
1 change: 0 additions & 1 deletion dart_ping_ios/.flutter-plugins-dependencies

This file was deleted.

6 changes: 6 additions & 0 deletions dart_ping_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.0.1

- Improve usage docs
- Add repository link to pubspec
- Fix typos
- Update / improve flutter example
## 2.0.0

- Support dart_ping 7.0.0
Expand Down
28 changes: 22 additions & 6 deletions dart_ping_ios/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
This package adds iOS support to the [dart_ping](https://pub.dev/packages/dart_ping) package via registration.

The [dart_ping](https://pub.dev/packages/dart_ping) is required for use.
The [dart_ping](https://pub.dev/packages/dart_ping) package is required for use.

Created from templates made available by Stagehand under a BSD-style
[license](https://github.com/dart-lang/stagehand/blob/master/LICENSE).

## Usage

A simple usage example:
The key to using this package is to import it and call this method before you use dart_ping:

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

void main() {
// Register dart_ping_ios with dart_ping
// You only need to call this once
DartPingIOS.register();
}

```

You only need to call this once. I usually do this somewhere in my main method before my app runs.

Here is a simple but full example based on the Flutter counter app:

```dart
import 'package:dart_ping/dart_ping.dart';
Expand All @@ -25,7 +40,7 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'DartPing iOS Demo',
title: 'DartPing Flutter Demo',
home: MyHomePage(),
);
}
Expand Down Expand Up @@ -55,7 +70,7 @@ class _MyHomePageState extends State<MyHomePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('DartPing iOS Demo'),
title: Text('DartPing Flutter Demo'),
),
body: Center(
child: Column(
Expand All @@ -69,12 +84,13 @@ class _MyHomePageState extends State<MyHomePage> {
),
floatingActionButton: FloatingActionButton(
onPressed: _startPing,
tooltip: 'Increment',
child: Icon(Icons.add),
tooltip: 'Start Ping',
child: Icon(Icons.radar_sharp),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}

```

## Features and bugs
Expand Down
33 changes: 31 additions & 2 deletions dart_ping_ios/example/.metadata
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
# This file should be version controlled.

version:
revision: f4abaa0735eba4dfd8f33f73363911d63931fe03
revision: f1875d570e39de09040c8f79aa13cc56baab8db1
channel: stable

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
- platform: android
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
- platform: ios
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
- platform: macos
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
- platform: web
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
7 changes: 7 additions & 0 deletions dart_ping_ios/example/macos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Flutter-related
**/Flutter/ephemeral/
**/Pods/

# Xcode-related
**/dgph
**/xcuserdata/
2 changes: 2 additions & 0 deletions dart_ping_ios/example/macos/Flutter/Flutter-Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
2 changes: 2 additions & 0 deletions dart_ping_ios/example/macos/Flutter/Flutter-Release.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
Loading