salbahra / cordova-plugin-networkinterface Goto Github PK
View Code? Open in Web Editor NEWProvide a method for Cordova applications to retrieve the device IP Address.
Home Page: http://albahra.com/projects
Provide a method for Cordova applications to retrieve the device IP Address.
Home Page: http://albahra.com/projects
Hi Samer,
I trying to use your plugin... I can see alert in sample function you provide comes with information but I am unable to modify it at all. The simple change of assigning ip to a different variable does not work ...alert in the code below comes always with info ... but variable afterwards remains undefined. Any guidelines where to look for will be greatly appreciated.
var ownIP;
function setOwnIP(){
networkinterface.getIPAddress(function (ip) { alert(ip); ownIP = ip; });
}
rgds
Juan Antonio
For the cell/3g network I get the onError callback with null.
But on WiFi I am successfully able to get the IP in the onSuccess callback.
Platform: iOS 9.x
Hi, first thank you for this great plugin.
Is it possible to retrieve the VPN ip address too if it is connected ?
Or a json array with all available connections, the device could be connected with ethernet for example
regards
I tried to use this plugin to get the local ip address.
inside a angular2 (maybe also angular1) application the console shows a lot of errors.
i figured out that "use strict" will be added by transpiler typescript or other javascript compilers.
Is it possible to fix the plugin to work with "use strict"?
Does someone has the same issue?
Hi,
I've been trying to collect client IP using this plugin. For Native device it works fine, but for browsers, it says cordova_not_found.
How to resolve this.
The Wi-Fi ip address cannot be obtained in ios 16.3;The error message is No valid
IP address identified
i used ionic 2
i install plugin cordova-plugin-networkinterface
cordova plugin add cordova-plugin-networkinterface
and after i used code
networkinterface.getIPAddress(function (ip) { alert(ip); });
but it error " networkinterface is not defined"
I'm in the middle of debugging why my Ionic 3 application is unable to communicate with the internet. I've been able to confirm that my application receives an IP address using this helpful plugin, however, I cannot receive any proxy information of websites, which I think is a clue.
Upon calling getWifiAddress(), I get : WIFI IP: 10.66.61.134, Subnet: 255.255.224.0
However, upon calling getHttpProxyInformation('www.github.com'), I get : Unable to get proxy info: Error while calling ''getHttpProxyInformation' 'protocol = null, host = null
I believe this is unusual and unexpected.
So how can the app both have a valid IP / Sub but not get proxy information regarding a website? The app is connected to a functional network.
Is this a permissions issue? My Config.xml contains the following lines which I believe are relevant:
I am trying to log the public IP address of the client device when authenticating, but on carrier mode, I get IP address as 0.0.0.0, is this expected? Also on the wifi, I get the LAN IP and not the public IP.
On Windows 10 I get the error Missing Command Error
when calling getIPAddress. I guess you support only WP8 right?
Could you add the same functionality for Windows 10 please?
This occurs on the latest 9 Cordova version (as well as a previous one that I updated from, I believe 8.x).
Referencing : #39
Just installing the plugin and running the app springs up this error.
2019-04-12 11:59:30.979 21202-21310/com. W/CordovaPlugin: Attempted to send a second callback for ID: networkinterface1757067064
Result was: "Invalid action"
2019-04-12 11:59:30.981 21202-21310/com. W/CordovaPlugin: Attempted to send a second callback for ID: networkinterface1757067065
Result was: "Invalid action"
This appears to explain the error (or be a symptom of) when I call getHttpProxyInformation:
Unable to get proxy info: Error while calling ''getHttpProxyInformation' 'protocol = null host = null
2019-04-12 11:59:30.992 21202-21202/com.GPSWalking.Team10 I/chromium: [INFO:CONSOLE(157)] "Unable to get proxy info: Error while calling ''getHttpProxyInformation' 'protocol = null host = null", source: http://192.168.1.128:8100/__ion-dev-server/ion-dev.js?v=3.2.2 (157)
Hello thanks for great plugin,
I tried get IP address from Browser that I used iframe for simulator
What I had read on Doc it said:
Supported platforms
Android
BlackBerry 10
Browser
iOS
Windows
Windows Phone
but it seems I could not able to get IP address code I followed on doc:
this.networkInterface.getWiFiIPAddress(function (ip) { alert(ip); });
this.networkInterface.getCarrierIPAddress(function (ip) { alert(ip); });
thanks for your help!
For what it's worth: it's late 2019 and I can confirm that this plugin works for Cordova with iOS and Android, and does not - as stated in #20 - work with the browser platform (ergo also not for Electron).
However, this code works for the browser platform:
https://ourcodeworld.com/articles/read/257/how-to-get-the-client-ip-address-with-javascript-only
Hope, this helps someone.
In my code, I put the getIPAddress
function in platform.ready()
constructor(
public platform: Platform,
public networkInterface:NetworkInterface
) {
this.platform.ready().then(() => {
this.networkInterface.getIPAddress().then(ipAddress => {
console.log("ip-success:", ipAddress);
}).catch(error => {
console.error("ip-error:",error);
});
});
}
When I run these code on ios device, I get these console.warn
console.warn: "Native: tried calling NetworkInterface.getIPAddress, but the NetworkInterface plugin is not installed. "
console.warn: Install the NetworkInterface plugin: 'ionic cordova plugin add cordova-plugin-networkinterface'
and my error print
console.error: ip-error:plugin_not_installed
It says the plugin is not installed, however, I have added the plugin before and these is related plugin configuration in config.xml file.
Any chance of expanding this to get signal strength and connection info (aka ssid or tower id)?
(crosses fingers)
This plugin doesn't seem to be maintained anymore, but in case anyone is using it and experiencing the issue mentioned in the title: This is because the plugin just goes through all en0 interfaces (which is wifi) and uses always the last one. It seems that there is sometimes more than one en0, but some of them with IP 0.0.0.0 (probably non-active ones). If one of the 0.0.0.0 happen to be looped through after the actual active en0 interface, the returned IP will be 0.0.0.0.
To patch this, you have to make some changes to CDVNetworkInterface.m
, line 22 (within the getInterfaceiIP
function):
Search for
if([name isEqualToString:interfaceName]
and change it to
if([name isEqualToString:interfaceName] && ![addr isEqualToString:@"0.0.0.0"])
Hope someone finds this helpful.
I know it's been an issue before but I'm still having this issue. Whether I add "window" or not is still the same (although a different error message). And I've also made it sure that it will only run after the device ready event has been received.
I've created the app using Phonegap CLI and built it on Phonegap Build.
I added this on my config.xml:
<gap:plugin name="cordova-plugin-networkinterface" source="npm" />
Here's what my javascript look like:
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
alert('Received Event: ' + id);
setTimeout(function(){
try{
networkinterface.getIPAddress(function (ip) {
alert("IP: "+ip);
function(error){
alert("IP Error: "+error);
});
}catch(e){alert(e)}
}, 1000);
}
};
I also tried it on runkit with the same result as mine which I got from NPM: https://runkit.com/589d9741aa6f95001497501d/589d9741aa6f95001497501e
Can you please take a closer look on what's causing this?
Thank you very much!
Would it be possible to add a function to also get the netmask of the network?
I use this plugin to get the ip address to scan a network for a server. To get the whole range of the network i use this plugin: IPSubnetCalculator
To geht the range i need the netmask.
Would be nice to get this feature in here ;)
Hey great plugin!
I followed your README instructions to use the new getWiFiIPAddress()
and getCarrierIPAddress()
instead of the old deprecated getIPAddress()
but it didn't work as I used cordova plugin add cordova-plugin-networkinterface
, which according to npm is only at version 1.0.8. Apparently the newer functions aren't defined in that version.
I guess the solution is to publish the latest version to npm or update your README to add from git master so your users aren't left confused.
Thanks again for the great plugin!
If I run getWiFiIPAddress()
in the browser by running ionic cordova run browser
, then alert shows IP address but if I run the same App is built for Android platform by ionic cordova run android
and check DevTools in chrome for logs, an object is displayed.
If I try to access .ip
and .subnet
, it says that the properties do no exist.
Please help!
Q1
is there any plan to develop in Android or WP
Q2
in PGB 3.3,it should be
window.networkinterface.getIPAddress(....)
I never used Angular.
I am facing networkinterface is not defined
..what could be a reason ?
In index.html
<script>
try {
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
networkinterface.getIPAddress(function (ip) { alert(ip); });
}
} catch (er) { alert(er); }
</script>
Hi, this plugin looks exactly like what I need, but I'm not fully sure how to use it in Ionic... any idea? How can I access this object?
Hello,
thanks for this great plugin! Would it be possible to add the router IP address also?
Thanks!
Recommend checking only for sa_type == AF_INET
as we cannot reliably convert all IPv6 addresses to IPv4 (Given there are more IPv6 addresses available than IPv4). We could make a new method specifically for IPv6 maybe?
In my testing inet_ntoa converts IPv6 to 0.0.0.0
Hi,
When I try to do cordova plugin add, I get this error:
ENOENT: no such file or directory, open '/Users/abu/Desktop/Solutions/neonbanking-frontend/node_modules/cordova-android/bin/templates/app/src/main/AndroidManifest.xml'
The same error appears on cordova-android 9.0.0 and 10.1.1
When I open the directory of cordova-android in node_modules, the manifest is there, but at a slightly different path.
Could it be that this plugin doesn't work on certian cordova-android versions?
running ionic 2.2.2, cordova 6.5.0
I did a console.log of the data
console.log("ni="+ networkinterface);
ni=function(){
}
console.log("ni="+ networkinterface.getWifiIPAddress);
ni=undefined
no idea what is going on.. help
200 /plugins/cordova-plugin-networkinterface/www/networkinterface.js
Can't find variable: networkinterface
and TypeError: networkinterface.getWiFiIPAddress is not a function (which is expected if it is undefined).
Could you add a WebRTC fallback for unsupported platforms? That's useful especially in desktop web browsers.
That should work in any recent browser, even on some smartphones I think.
Here's a question on stackoverflow that discovers the local IP address of the machine using WebRTC:
http://stackoverflow.com/questions/18572365/get-local-ip-of-a-device-in-chrome-extension
according to this
http://phonegap.com/blog/2015/05/26/npm-plugins-available/
http://cordova.apache.org/announcements/2015/04/21/plugins-release-and-move-to-npm.html
so...your plugin should be move to npm in the future...
Hi,
When I use your plugin, I get an IP address that is not the actual one. I get a 10.0.x.x IP while my device info shows an 192.168.x.x (my dhcp configuration)
When I read your code, I see that you return the first address found.... could you return every addresses in getIPAddresses?
Thx and good job!!!
I am having trouble that this plugin works on IOS but not on android, in the repo it says it supports Android, Browser, iOS, and Windows 10 (I doubt that), and on the owner's website (https://albahra.com/projects) it is only listing IOS...
What is true here, am I wasting time trying to make this run on android or am I making a mistake somewhere?
getting issue networkinterface.getCarrierIPAddress
is not a function, if i use networkinterface.getIPAddress
this only return IP for wifi, if device using mobile data than return ip undefined.
Using the Quasar framework and wanted to easily grab the devices IP.
In the src-cordova
folder I ran:
cordova plugin add cordova-plugin-networkinterface
Added <plugin name="cordova-plugin-networkinterface" source="npm" />
to the config.xml
Then, once the Vue component is mounted, I run:
networkinterface.getWiFiIPAddress( onSuccess, onError );
But networkinterface is always undefined. I thought this plugin added a global reference to networkinterface?
It would be great if the plugin contained a function to get the first available IPAddress, trying to get wifi IP Address and, if it's not available, gets Carrier IP Address.
Hi,
I'm unable to fetch the CarrierIPAddress
Getting error response as : No valid IP address identified
This plugin looks great, we would like to ask for a feature request on android and ios,
We need the ipaddress for the GW/Router the device is connected. I had a look on android and there is the possibility to do this, probably also on ios.
Could you have a look for it and integrate it.
FYI:
Perhaps if anything is working great, we would like in feature to propose to the ionic team to integrate this as ionic-native. If we find the time we can open a pull request on them. What do you think about it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.