Non-server side method of getting local IP address in browser?
ip-address
Solution
Thankfully to Webrtc it is possible to access local IP from javascript.
Take a look at: http://net.ipcalf.com/ (source)
( It works in chrome )
However accessing local IP from Javascript could be a privacy and security issue.
and below simpler example then net.ipcalf.com
and on the jsfiddle
var RTCPeerConnection = window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
var configuration = { "iceServers": [] };
var pc;
var localIP;
if(RTCPeerConnection){
pc = new RTCPeerConnection(configuration);
pc.onicecandidate = function (evt) {
if (evt.candidate) {
if (!localIP) {
localIP = getIpFromString( evt.candidate.candidate );
console.log(localIP);
}
}
};
pc.createOffer(function (offerDesc) {;
pc.setLocalDescription(offerDesc);
}, function (e) { console.warn("offer failed", e); });
function getIpFromString(a)
{
var r = a.match(/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/);
return r[0];
}
} else {
//browser doesn't support webrtc
}
Problem
I am trying to provide a way for users on my LAN to "register" with the Network admin (me) without having to either a) host a page on my computer b) host a script on the central server (since it is only a router, not really a solid HTTP server) or c) sign up for a Dynamic Domain in order to either either of the first two and avoid the confusion of sending out a URL to a link to a local IP. Is there a simple way to display the local IP address on screen via a client-side script? I'm thinking maybe I could have an iframe that points to some generic url with some javascript in the path, so that I can have the users go to a non-local site, and the iframe would pop up with their IP address that they can then enter into a form in the main remote page. If all else fails, is there a way for them to look up their IP that is cross-platform and doesn't involve using the command line (I think the first, even if impossible, is probably more realistic than the second).