Coder Social home page Coder Social logo

gdbwarez / cordova-plugin-networkinterface Goto Github PK

View Code? Open in Web Editor NEW

This project forked from salbahra/cordova-plugin-networkinterface

0.0 2.0 0.0 70 KB

Provide a method for Cordova applications to retrieve the device IP Address.

Home Page: http://albahra.com/projects

Java 43.27% JavaScript 16.71% Objective-C 40.02%

cordova-plugin-networkinterface's Introduction

Network Interface

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

To include the Network Interface plugin in your PhoneGap Build application, add this to your config.xml:

<plugin name="cordova-plugin-networkinterface" source="npm" />

Ionic 2+ (w/ Typescript) Usage

First install the wrapper:

npm install @ionic-native/network-interface

Define it in your modules:

import { NetworkInterface } from '@ionic-native/network-interface';

@NgModule( {
    ...
    providers: [
        NetworkInterface
    ],
} )

The Ionic wrapper functions return promises, so use them as follows:

import { NetworkInterface } from '@ionic-native/network-interface';

constructor( private networkInterface: NetworkInterface ) {

  this.networkInterface.getWiFiIPAddress()
    .then(address => console.info(`IP: ${address.ip}, Subnet: ${address.subnet}`))
    .catch(error => console.error(`Unable to get IP: ${error}`));

  this.networkInterface.getCarrierIPAddress() {
    .then(address => console.info(`IP: ${address.ip}, Subnet: ${address.subnet}`))
    .catch(error => console.error(`Unable to get IP: ${error}`));

  const url = 'www.github.com';
  this.networkInterface.getHttpProxyInformation(url)
    .then(proxy => console.info(`Type: ${proxy.type}, Host: ${proxy.host}, Port: ${proxy.port}`))
    .catch(error => console.error(`Unable to get proxy info: ${error}`));
}

Global Usage

The plugin creates the global object networkinterface, with the following methods:

  • getWiFiIPAddress(onSuccess, onError)
  • getCarrierIPAddress(onSuccess, onError)
  • getHttpProxyInformation (url, 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.

function onSuccess( ipInformation ) {
  alert( "IP: " + ipInformation.ip + " subnet:" + ipInformation.subnet );
}

function onError( error ) {
  // Note: onError() will be called when an IP address can't be
  // found, e.g. WiFi is disabled, no SIM card, Airplane mode
  alert( error );
}

networkinterface.getWiFiIPAddress( onSuccess, onError );
networkinterface.getCarrierIPAddress( onSuccess, onError );

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"

// The url you want to find out the proxies for.
const url = 'www.github.com';

function onSuccess( proxyInformation ) {
  proxyInformation.forEach( function( proxy ) {
    alert( "Type:" + proxy.type + " Host:" + proxy.host + " Port:" + proxt.port );
  });
}

function onError( error ) {

    // Note: onSuccess() will be called where there is no applicable proxy, not onError.
    alert( error );
}

networkinterface.getHttpProxyInformation( url, onSuccess, onError );

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"

License

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.