Aus öffentlichen Paketdaten erstellte Orientierung.
Ein Flutter-Paket, das VPN-Verbindungen auf Android, iOS, macOS, Windows und Linux mithilfe nativer Plattform-APIs erkennt. Es bietet einen Echtzeit-Stream von Änderungen im VPN-Status und unterstützt einmalige Überprüfungen zur Bestimmung der aktuellen Verbindung. Für Apps entwickelt, die den Einsatz von VPN überwachen oder darauf reagieren müssen, wie Sicherheitstools, netzwerkorientierte Anwendungen oder Datenschutz-dienstleistungen. Das Paket gewährleistet zuverlässige Erkennung über Plattformen hinweg mit minimalem Setup.
Erkennen aller benutzerdefinierten oder Drittanbieter-VPNs nicht sicherstellen
Das Verhalten kann sich zwischen Plattformen leicht unterscheiden
Beschränkt auf die Erkennung aktiver VPN-Zustände, nicht detaillierter Konfiguration
Abhängig von der Zuverlässigkeit der Native-Implementierung
Original-README
Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.
VPN Connection Detector
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.
Why This Package?
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:
// Check if VPN is currently activebool isVpnConnected = awaitVpnConnectionDetector.isVpnActive();
if (isVpnConnected) {
print('VPN is connected');
} else {
print('VPN is not connected');
}
Real-time VPN Status Stream
final vpnDetector = VpnConnectionDetector();
// Listen to VPN status changes
vpnDetector.vpnConnectionStream.listen((state) {
switch (state) {
caseVpnConnectionState.connected:
print('VPN connected');
break;
caseVpnConnectionState.disconnected:
print('VPN disconnected');
break;
}
});
// Don't forget to dispose when done
vpnDetector.dispose();
Get Detailed VPN Information
final info = awaitVpnConnectionDetector.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'
}
Access Current Cached State
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"}');
API Reference
VpnConnectionDetector
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
VpnConnectionState
enumVpnConnectionState {
connected, // VPN is currently connected
disconnected, // VPN is currently disconnected
}
Version 2.0 introduces native platform support with a cleaner API:
// v1.x (still works)final isActive = awaitVpnConnectionDetector.isVpnActive();
final detector = VpnConnectionDetector();
detector.vpnConnectionStream.listen((state) { ... });
// v2.0 (new features)final info = awaitVpnConnectionDetector.getVpnInfo();
print('Protocol: ${info?.vpnProtocol}');
Breaking changes:
Minimum iOS version: 12.0
Minimum Android SDK: 21
Removed web platform support (not possible to detect VPN in browsers)
How It Works
iOS
VPN detection: Uses 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.
Real-time monitoring: Uses NWPathMonitor to detect network changes and re-evaluate VPN status
App Store safe: Does not use NEVPNManager or any APIs that require the Network Extension entitlement
Android
Uses ConnectivityManager with NetworkCapabilities.TRANSPORT_VPN for accurate VPN detection on API 23+. This detects all VPN connections regardless of the VPN app used.
Desktop (Fallback)
Inspects network interface names for common VPN patterns (tun, tap, ppp, wireguard, etc.).
Contributing
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
License
This project is licensed under the MIT License - see the LICENSE file for details.