vpn_connection_detector
Flutter용 네이티브 iOS 및 안드로이드 지원을 갖춘 VPN 연결 감지. 실시간 상태 스트림 및 일회성 확인 포함.
VpnConnectionDetector는 VPN의 연결 상태를 모니터링하는 Dart 패키지입니다. VpnConnectionState 이벤트 스트림과 VPN이 연결되어 있는지 확인하는 메서드를 제공하는 싱글톤 클래스를 제공합니다.
^7.2.0{"sdk":"flutter"}^2.1.8{"sdk":"flutter"}^6.0.0아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
The most accurate VPN detection package for Flutter — with native iOS & Android implementations that detect both system-configured VPNs and third-party VPN apps like NordVPN, ExpressVPN, ProtonVPN, and more.
Most VPN detection solutions only check for system-configured VPNs, missing the majority of users who use third-party VPN apps. This package uses platform-native APIs to detect VPNs with ~95% accuracy:
CFNetworkCopySystemProxySettings and NWPathMonitorNetworkCapabilities.TRANSPORT_VPN| Platform | Native | Accuracy | Notes |
|---|---|---|---|
| iOS | ✅ | ~95% | Uses CFNetworkCopySystemProxySettings & NWPathMonitor |
| Android | ✅ | ~95% | Uses NetworkCapabilities API |
| macOS | ❌ | ~70-80% | Dart fallback (interface name matching) |
| Windows | ❌ | ~70-80% | Dart fallback |
| Linux | ❌ | ~70-80% | Dart fallback |
Add vpn_connection_detector to your pubspec.yaml:
dependencies:
vpn_connection_detector: ^2.0.1
Add the following permission to your AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
No additional setup required. The plugin uses system frameworks that are available by default.
import 'package:vpn_connection_detector/vpn_connection_detector.dart';
// Check if VPN is currently active
bool isVpnConnected = await VpnConnectionDetector.isVpnActive();
if (isVpnConnected) {
print('VPN is connected');
} else {
print('VPN is not connected');
}
final vpnDetector = VpnConnectionDetector();
// Listen to VPN status changes
vpnDetector.vpnConnectionStream.listen((state) {
switch (state) {
case VpnConnectionState.connected:
print('VPN connected');
break;
case VpnConnectionState.disconnected:
print('VPN disconnected');
break;
}
});
// Don't forget to dispose when done
vpnDetector.dispose();
final info = await VpnConnectionDetector.getVpnInfo();
if (info != null && info.isConnected) {
print('VPN Connected');
print('Interface: ${info.interfaceName}'); // e.g., 'utun3', 'tun0'
print('Protocol: ${info.vpnProtocol}'); // e.g., 'WireGuard', 'IKEv2'
}
final vpnDetector = VpnConnectionDetector();
// Get the last known state (may be null if not yet determined)
final currentState = vpnDetector.currentState;
print('Current state: ${currentState?.name ?? "unknown"}');
| Method/Property | Type | Description |
|---|---|---|
isVpnActive() |
static Future<bool> |
One-time check if VPN is active |
getVpnInfo() |
static Future<VpnInfo?> |
Get detailed VPN information |
vpnConnectionStream |
Stream<VpnConnectionState> |
Real-time status stream |
currentState |
VpnConnectionState? |
Last known VPN state |
dispose() |
void |
Clean up resources |
enum VpnConnectionState {
connected, // VPN is currently connected
disconnected, // VPN is currently disconnected
}
class VpnInfo {
final bool isConnected; // Whether VPN is connected
final String? interfaceName; // Network interface name (e.g., 'utun3')
final String? vpnProtocol; // Detected VPN protocol (e.g., 'WireGuard')
}
See the example directory for a complete sample app.
import 'package:flutter/material.dart';
import 'package:vpn_connection_detector/vpn_connection_detector.dart';
class VpnStatusWidget extends StatelessWidget {
final _vpnDetector = VpnConnectionDetector();
@override
Widget build(BuildContext context) {
return StreamBuilder<VpnConnectionState>(
stream: _vpnDetector.vpnConnectionStream,
builder: (context, snapshot) {
final isConnected = snapshot.data == VpnConnectionState.connected;
return Icon(
isConnected ? Icons.vpn_lock : Icons.vpn_lock_outlined,
color: isConnected ? Colors.green : Colors.grey,
);
},
);
}
}
Version 2.0 introduces native platform support with a cleaner API:
// v1.x (still works)
final isActive = await VpnConnectionDetector.isVpnActive();
final detector = VpnConnectionDetector();
detector.vpnConnectionStream.listen((state) { ... });
// v2.0 (new features)
final info = await VpnConnectionDetector.getVpnInfo();
print('Protocol: ${info?.vpnProtocol}');
Breaking changes:
CFNetworkCopySystemProxySettings to inspect the __SCOPED__ dictionary, which only contains active VPN network interfaces — this reliably detects both system-configured VPNs and third-party apps like NordVPN, ExpressVPN, ProtonVPN, Surfshark, etc.NWPathMonitor to detect network changes and re-evaluate VPN statusNEVPNManager or any APIs that require the Network Extension entitlementUses ConnectivityManager with NetworkCapabilities.TRANSPORT_VPN for accurate VPN detection on API 23+. This detects all VPN connections regardless of the VPN app used.
Inspects network interface names for common VPN patterns (tun, tap, ppp, wireguard, etc.).
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.