react-native-vpn-proxy-detect
v0.1.0
Published
Checks for VPN & Proxy connections
Maintainers
Readme
react-native-vpn-proxy-detect
A React Native library for detecting VPN and Proxy connections on iOS and Android devices.
Features
- ✅ Detect VPN connections
- ✅ Detect Proxy connections
- ✅ iOS and Android support
- ✅ TypeScript support
- ✅ Turbo Module architecture
- ✅ Promise-based API
Installation
npm install react-native-vpn-proxy-detectiOS
Run cd ios && pod install to install the iOS dependencies.
Android
No additional setup required for Android.
Usage
Import Methods
// Named imports (recommended)
import { detectVPN, detectProxy } from 'react-native-vpn-proxy-detect';
// Default import (for backward compatibility)
import VpnProxyDetect from 'react-native-vpn-proxy-detect';Detect VPN Connection
import { detectVPN } from 'react-native-vpn-proxy-detect';
async function checkVPN() {
try {
const isVPNActive = await detectVPN();
console.log('VPN is active:', isVPNActive);
} catch (error) {
console.error('Failed to detect VPN:', error);
}
}Detect Proxy Connection
import { detectProxy } from 'react-native-vpn-proxy-detect';
async function checkProxy() {
try {
const isProxyActive = await detectProxy();
console.log('Proxy is active:', isProxyActive);
} catch (error) {
console.error('Failed to detect proxy:', error);
}
}Check Both VPN and Proxy
import { detectVPN, detectProxy } from 'react-native-vpn-proxy-detect';
async function checkNetworkSecurity() {
try {
const [vpnResult, proxyResult] = await Promise.all([
detectVPN(),
detectProxy()
]);
console.log('VPN Status:', vpnResult ? 'Active' : 'Inactive');
console.log('Proxy Status:', proxyResult ? 'Active' : 'Inactive');
} catch (error) {
console.error('Failed to detect network status:', error);
}
}Using Default Export (Backward Compatibility)
import VpnProxyDetect from 'react-native-vpn-proxy-detect';
async function checkSecurity() {
try {
const vpnActive = await VpnProxyDetect.detectVPN();
const proxyActive = await VpnProxyDetect.detectProxy();
console.log('VPN:', vpnActive);
console.log('Proxy:', proxyActive);
} catch (error) {
console.error('Detection failed:', error);
}
}API Reference
detectVPN(): Promise<boolean>
Detects if a VPN connection is currently active.
Returns: Promise that resolves to true if VPN is active, false otherwise.
Throws: Error if detection fails.
detectProxy(): Promise<boolean>
Detects if a proxy connection is currently active.
Returns: Promise that resolves to true if proxy is active, false otherwise.
Throws: Error if detection fails.
Platform-Specific Implementation
iOS
- Uses
CFNetworkCopySystemProxySettings()to detect VPN connections by checking for network interfaces liketap,tun,ppp,ipsec, andutun - Uses
CFNetworkCopyProxiesForURL()to detect proxy settings
Android
- Uses
ConnectivityManagerandNetworkCapabilitiesto detect VPN connections - Checks system properties for proxy configuration
Example App
The library includes a complete example app demonstrating all features. To run it:
# Install dependencies
yarn
# Run on iOS
yarn example ios
# Run on Android
yarn example androidMigration from react-native-vpn-detect
This library is a modernized version of react-native-vpn-detect with the following improvements:
- New import syntax: Use named imports instead of default export
- Turbo Module: Better performance and future-proof architecture
- TypeScript: Full TypeScript support out of the box
- Modern tooling: Latest React Native development tools
Migration Guide
Old usage:
import Security from "react-native-vpn-detect";
const vpnActive = await Security.detectVPN();
const proxyActive = await Security.detectProxy();New usage:
import { detectVPN, detectProxy } from 'react-native-vpn-proxy-detect';
const vpnActive = await detectVPN();
const proxyActive = await detectProxy();Contributing
License
MIT
Made with create-react-native-library
