Socket
Socket
Sign inDemoInstall

cordova-plugin-networkinterface

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cordova-plugin-networkinterface - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0

15

package.json
{
"name": "cordova-plugin-networkinterface",
"version": "1.2.0",
"description": "This plugin allows your application to retrieve the local wifi address.",
"version": "2.0.0",
"description": "This plugin allows your application to retrieve the local wifi address and http proxy information.",
"cordova": {

@@ -10,4 +10,4 @@ "id": "cordova-plugin-networkinterface",

"android",
"wp8",
"blackberry10"
"browser",
"windows"
]

@@ -24,7 +24,8 @@ },

"network",
"proxy",
"ecosystem:cordova",
"cordova-ios",
"cordova-android",
"cordova-wp8",
"cordova-blackberry10"
"cordova-browser",
"cordova-windows"
],

@@ -37,3 +38,3 @@ "engines": [

],
"author": "Samer Albahra",
"author": "Samer Albahra, tombolaLtd",
"license": "MIT",

@@ -40,0 +41,0 @@ "bugs": {

Network Interface
=================
Network interface information plugin for Cordova/PhoneGap that supports Android, Blackberry 10, Browser, iOS, and Windows Phone 8.
Network interface information plugin for Cordova/PhoneGap that supports Android, Browser, iOS, and Windows 10.
## Command Line Install
cordova plugin add cordova-plugin-networkinterface
## PhoneGap Build

@@ -12,43 +16,88 @@

## Command Line Install
## Ionic 2+ (w/ Typescript) Usage
cordova plugin add cordova-plugin-networkinterface
First install the wrapper:
## Usage
```sh
npm install @ionic-native/network-interface
```
The plugin creates the object `networkinterface` with the methods:
Define it in your modules:
```ts
import { NetworkInterface } from '@ionic-native/network-interface';
@NgModule( {
...
providers: [
NetworkInterface
],
} )
```
Then use it as follows:
```ts
import { NetworkInterface } from '@ionic-native/network-interface';
constructor( private networkInterface: NetworkInterface ) {
this.networkInterface.getWiFiIPAddress( ip => alert( ip ) );
this.networkInterface.getCarrierIPAddress( ip => alert( ip ) );
}
```
## Global Usage
The plugin creates the global object `networkinterface`, with the following methods:
* getWiFiIPAddress(onSuccess, onError)
* getCarrierIPAddress(onSuccess, onError)
* getHttpProxyInformation (url, onSuccess, onError)
* getIPAddress(onSuccess, onError)
### Using getWiFiIPAddress and getCarrierIPAddress
The onSuccess() callback has one argument object with the properties `ip` and `subnet` (changed in 2.x). The onError() callback is provided with a single value describing the error.
`This method is deprecated and uses the getWiFiIPAddress method.`
```javascript
function onSuccess( ipInformation ) {
alert( "IP: " + ipInformation.ip + " subnet:" + ipInformation.subnet );
}
The onSuccess() callback is provided with two values:
function onError( error ) {
function onSuccess(ip, subnet) { }
// Note: onError() will be called when an IP address can't be found. eg WiFi is disabled, no SIM card, Airplane mode etc.
alert( error );
}
`Note: Subnet is only supported for iOS and Android currently`
networkinterface.getWiFiIPAddress( onSuccess, onError );
networkinterface.getCarrierIPAddress( onSuccess, onError );
```
The onError() callback is provided with a single value:
### Using getHttpProxyInformation
This function gets the relevant proxies for the passed URL in order of application. `onSuccess` we will get an array of objects, each having a `type`, `host` and `port` property. Where the url is not passed via a proxy, the `type` is "DIRECT" and both the host and port properties are set to "none"
function onError(error) { }
```javascript
var url = "www.github.com"; //The url you want to find out the proxies for.
`Note: onError() will be called when an IP address can't be found. eg WiFi is disabled, no SIM card, Airplane mode etc.
`
function onSuccess( proxyInformation ) {
proxyInformation.forEach( function( proxy ) {
alert( "Type:" + proxy.type + " Host:" + proxy.host + " Port:" + proxt.port );
} );
}
Example:
function onError( error ) {
networkinterface.getWiFiIPAddress(function (ip) { alert(ip); });
networkinterface.getCarrierIPAddress(function (ip) { alert(ip); });
// with subnet and error handler
networkinterface.getWiFiIPAddress(
function (ip, subnet) { alert(ip + ":" + subnet); },
function (err) { alert("Err: " + err); }
);
// Note: onSuccess() will be called where there is no applicable proxy, not onError.
alert( error );
}
## TODO
networkinterface.getHttpProxyInformation( url, resolve, reject );
```
getCarrierIPAddress() is currently supported on iOS and Android only, need to add Blackberry 10, Browser, and Windows Phone 8 support
The type can be any of the following:
* DIRECT - Not passing through a proxy. `host`/`port` values will be "none"
* SOCKS
* HTTP
* HTTPS - iOS Only, seems to default back to HTTP
* AUTOJS - iOS Only, proxy determined by AutoConfiguration Script. `host`/`port` values will be "none"
* AUTOCONFIG - iOS Only, proxy determined by configuration at a URK `host`/`port` values will be "none"

@@ -55,0 +104,0 @@ ## License

function getWiFiIPAddress(success, failure) {
var winNetConn = Windows.Networking.Connectivity;
var networkInfo = winNetConn.NetworkInformation;
var hostnames = networkInfo.getHostNames();
var addresses = [];
for (const hostname of hostnames) {
if (hostname.ipInformation !== null && (hostname.ipInformation.networkAdapter.ianaInterfaceType == 71 || hostname.ipInformation.networkAdapter.ianaInterfaceType == 6)) {
addresses.push(hostname.displayName);
var winNetConn = Windows.Networking.Connectivity;
var networkInfo = winNetConn.NetworkInformation;
var hostnames = networkInfo.getHostNames();
var addresses = [];
for (const hostname of hostnames) {
if (hostname.ipInformation !== null && (hostname.ipInformation.networkAdapter.ianaInterfaceType == 71 || hostname.ipInformation.networkAdapter.ianaInterfaceType == 6)) {
addresses.push(hostname.displayName);
}
}
if (addresses.length) {
success(addresses[0]);
} else {
failure();
}
}
if (addresses.length) {
success(addresses[0]);
} else {
failure();
}
}
module.exports = {
getWiFiIPAddress: getWiFiIPAddress
};
require('cordova/exec/proxy').add('networkinterface', module.exports);
module.exports = {
getWiFiIPAddress: getWiFiIPAddress
};
require('cordova/exec/proxy').add('networkinterface', module.exports);
var networkinterface = function() {
};
networkinterface.getIPAddress = function( success, fail ) {
cordova.exec( success, fail, "networkinterface", "getWiFiIPAddress", [] );
};
networkinterface.getWiFiIPAddress = function( success, fail ) {

@@ -16,2 +12,6 @@ cordova.exec( success, fail, "networkinterface", "getWiFiIPAddress", [] );

networkinterface.getHttpProxyInformation = function(url, success, fail ) {
cordova.exec( success, fail, "networkinterface", "getHttpProxyInformation", [url] );
};
module.exports = networkinterface;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc