패키지, 저장소 및 앱 카테고리 검색

패키지 상세v10.0.1

dart_ping

네이티브 데스크톱 및 안드로이드 애플리케이션용 다중 플랫폼 네트워크 핑 유틸리티.

AndroidiOSmacOSWindowsLinux
30일 다운로드
5.3만
좋아요
134
Pub 점수
150

패키지 설치

flutter pub add dart_ping

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

dart_ping은 데스크톱 및 안드로이드 애플리케이션용으로 네이티브 핑 기능을 제공하는 다중 플랫폼 네트워크 유틸리티입니다. 개발자는 타겟 호스트에 ICMP 에코 요청을 보내어 네트워크 연결 상태를 확인할 수 있으며, 가용성과 지연 시간에 대한 실시간 피드백을 제공합니다. 크로스플랫폼 사용을 위해 설계되어 Android, iOS, macOS, Windows, Linux를 지원하며, 신뢰할 수 있는 네트워크 진단이 필요한 앱에 적합합니다. 간단한 add 명령어를 통해 Flutter 프로젝트에 원활하게 통합되며, 최적의 성능을 위해 플랫폼별 구현을 활용합니다.

사용 사례

  • 원격 서버로의 장치 연결 확인
  • 실시간으로 네트워크 지연 모니터링
  • 앱 시작 중 인터넷 액세스 검증
  • 모니터링 도구에 네트워크 건강 검사 통합
  • 로컬 네트워크 반응성 테스트

주요 기능

  • 주요 OS에서의 크로스 플랫폼 지원
  • 네이티브 ICMP 핑 구현
  • 저수준 네트워크 도달 가능성 테스트
  • Flutter와의 간단한 API 통합
  • 실시간 응답 시간 측정

적합한 대상

  • 네트워크 진단 도구
  • 사물인터넷 장치 연결 앱
  • 네트워크 건강 상태 확인이 필요한 모바일 및 데스크톱 앱
  • 시스템 모니터링 유틸리티
  • 강력한 연결 검증이 필요한 앱

고려 사항

  • 일부 플랫폼에서는 적절한 시스템 권한이 필요합니다
  • 방화벽 또는 네트워크 정책에 의해 차단될 수 있습니다
  • ICMP 기반 핑에 한정됨 (TCP/HTTP 대안 없음)
  • 플랫폼별 동작은 다를 수 있습니다
  • 시스템 제약으로 인해 고주파 폴링에 적합하지 않습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Dart Ping

Multi-platform network ping utility for Dart and Flutter applications, available via the pub.dev package repository.

One package, every platform

There is one package for every platform — add only dart_ping:

  • Windows, macOS, Linux, Android are served natively by the ping subprocess — no extra binaries.
  • iOS is served by a bundled native Swift ICMP engine driven over dart:ffi. The engine is compiled into the app by a Dart build hook only when the build target is iOS. It builds under Flutter's Swift Package Manager (SPM) mode with no CocoaPods Podfile, and requires the dart_ping 10.x SDK floor (Dart 3.10 / Flutter 3.38).

Pure-Dart consumers (CLI, server) are unaffected: with no iOS target, no Swift is compiled and no Flutter SDK is required.

Migrating from dart_ping_ios: remove the dart_ping_ios dependency, delete the DartPingIOS.register() call, and raise your SDK floor to the dart_ping 10.x baseline — no other source change, since the public Ping API is otherwise unchanged. Prior dart_ping_ios releases remain published on pub.dev for consumers who cannot adopt the raised floor; this repository no longer carries that package. See the CHANGELOG for the full 10.0.0 migration guide (including the sealed PingEvent stream and the ipv6 → IpVersion change).

Usage

A simple usage example:

import 'package:dart_ping/dart_ping.dart';

void main() async {
  // Create ping object with desired args
  final ping = Ping('google.com', count: 5);

  // Begin ping process and listen for output
  ping.stream.listen((event) {
    print(event);
  });
}

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

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

stream.first yields whatever [PingEvent] arrives first — a PingResponse on success, but a PingError if that first probe times out or the host is unreachable — so branch on the type (or be ready for first to surface an error) rather than assuming a successful reply.

To print the underlying ping command that will be used (useful for debugging):

print('Running command: ${ping.command}')

To prematurely halt the process:

await ping.stop()
The event stream

Ping.stream is a Stream<PingEvent> — a sealed union with three subtypes. Branch on the type with an exhaustive switch:

ping.stream.listen((event) {
  switch (event) {
    case PingResponse(): // a successful probe reply (seq, ttl, time, ip)
    case PingError():    // a probe/run error (may carry seq/ip)
    case PingSummary():  // the terminal run summary — the final event
  }
});

Every probe event also carries a nullable RoundTripStats? stats snapshot (min/avg/max/stddev/jitter so far), and PingSummary exposes both stats and a derived packetLoss getter, so you can drive a live latency/loss view without waiting for the summary.

Selecting a network interface

Ping(host, interface: ...) binds the ping to a specific interface, accepting either an interface name (e.g. eth0) or a local source IP address (e.g. 192.168.1.5). To discover the host's available interfaces, use listNetworkInterfaces() and feed one back into a Ping:

final interfaces = await listNetworkInterfaces();
// Pick one — by name or by a source address — then bind a ping to it.
final ping = Ping('dart.dev', interface: interfaces.first.name);
await for (final event in ping.stream) {
  print(event);
}

On Windows you must pass back a source address (e.g. interfaces.first.addresses.first.address), not the name, because Windows ping binds only by source address; a bare interface name is rejected there. A source address round-trips on every platform.

Address Family (IPv4 / IPv6)

The IP address family is chosen with the ipVersion parameter, an exclusive selection: IpVersion.ipv4 pings over IPv4 only and IpVersion.ipv6 over IPv6 only. There is no "prefer one family" or dual-stack mode — IpVersion.ipv4 excludes IPv6 rather than preferring it. The default is IpVersion.ipv4.

// IPv6 only (the system ping is invoked with the -6 family flag on
// Linux/Android and Windows; iOS IPv6 is served by dart_ping's own native
// engine. The macOS subprocess path is IPv4-only and raises an explicit
// error for an IPv6 selection.)
final ping = Ping('google.com', ipVersion: IpVersion.ipv6);

Migrating from the ipv6 boolean: the old ipv6: true / ipv6: false flag has been replaced by ipVersion. Map ipv6: true → ipVersion: IpVersion.ipv6, and ipv6: false (or omitting it) → ipVersion: IpVersion.ipv4.

IPv6-only networks (NAT64)

On an IPv6-only cellular network (NAT64/DNS64), an IPv4 literal such as 1.1.1.1 can be unreachable unless the platform synthesizes an IPv6 path to it. Ping exposes a nat64Synthesis option that is enabled by default, so an IPv4 literal keeps working on iOS without any code change. The active synthesis happens on iOS (via dart_ping's native engine); on the subprocess platforms (Windows, macOS, Linux, Android) the option is a no-op that leaves the ping command unchanged. Pass nat64Synthesis: false to opt out and restore raw pass-through.

Non-English Language Support

To support OS languages other than English, you can override the parser (Portuguese shown here):

final parser = PingParser(
    responseRgx: RegExp(r'de (?<ip>.*): bytes=(?:\d+) tempo=(?<time>\d+)ms TTL=(?<ttl>\d+)'),
    summaryRgx: RegExp(r'Enviados = (?<tx>\d+), Recebidos = (?<rx>\d+), Perdidos = (?:\d+)'),
    timeoutRgx: RegExp(r'host unreachable'),
    timeToLiveRgx: RegExp(r''),
    unknownHostStr: RegExp(r'A solicitação ping não pôde encontrar o host'),
  );

final ping = Ping('google.com', parser: parser);

On Windows installations, you can force the codepage (437) of the console instead of providing a custom parser:

final ping = Ping('google.com', forceCodepage: true);

To override the character encoding to ignore non-utf characters:

final ping = Ping('google.com', encoding: Utf8Codec(allowMalformed: true));
macOS Release Build with App Sandbox

When building in release mode with app sandbox enabled, you must ensure you add the following entitlements to the Release.entitlements file in your macos folder:

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

Features and bugs

Please file feature requests and bugs at the issue tracker.

카테고리

의존성

의존성 목록 5 개

소스 저장소

이 패키지를 사용하는 프로젝트