Checks for VPN & Proxy connections
npm install react-native-vpn-proxy-detectA React Native library for detecting VPN and Proxy connections on iOS and Android devices.
- ✅ Detect VPN connections
- ✅ Detect Proxy connections
- ✅ iOS and Android support
- ✅ TypeScript support
- ✅ Turbo Module architecture
- ✅ Promise-based API
``sh`
npm install react-native-vpn-proxy-detect
Run cd ios && pod install to install the iOS dependencies.
No additional setup required for Android.
`js
// 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';
`
`js
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);
}
}
`
`js
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);
}
}
`
`js
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);
}
}
`
`js
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);
}
}
`
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.
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.
to detect VPN connections by checking for network interfaces like tap, tun, ppp, ipsec, and utun
- Uses CFNetworkCopyProxiesForURL() to detect proxy settings$3
- Uses ConnectivityManager and NetworkCapabilities to detect VPN connections
- Checks system properties for proxy configurationExample App
The library includes a complete example app demonstrating all features. To run it:
`sh
Install dependencies
yarnRun on iOS
yarn example iosRun on Android
yarn example android
`Migration 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
$3
Old usage:
`js
import Security from "react-native-vpn-detect";const vpnActive = await Security.detectVPN();
const proxyActive = await Security.detectProxy();
`New usage:
`js
import { detectVPN, detectProxy } from 'react-native-vpn-proxy-detect';const vpnActive = await detectVPN();
const proxyActive = await detectProxy();
``- Development workflow
- Sending a pull request
- Code of conduct
MIT
---
Made with create-react-native-library