Reputation: 43
I use laptop for both work and personal use. So it is sometimes attached to home network and sometimes to one of many possible working places networks'
I've been thinking about customizing my browser's home page and/or MDM theme (linux mint logon page, html5 capable), both consist on customizing an html page, maybe using javascript, but i should know where the laptop is.
Think about me going to office, i want info about server's statuses and links to office's servers (A, B, C); going to a customer place, i will need connection to office's external IPs (A*, B*), and customer servers (X, Y, Z); back home, i will like to have wheater info, news, my soccer's team results, twitter, and so. I can setup all this through javascript (for example, using a table or dictionary: places = {ip1: [A, B, C], ip2: [X, Y, Z]} or something like that.
I know there are lots of places talking about retrieving my public IP and so... but using them requires an active and open internet connection. Some of the places I will be using this have no internet access or it is required to use a proxy with login and password. Thus any solution involving a reference to external sites won't work (but customers use local intranet services i need to access).
I also try to keep it simple: the idea is building some fast index page. So I'd prefer NOT loading java in the pages (and I'm not sure if MDM html5 themes would support it)
So the question is: Is there any way for retrieving LOCAL IP (not public IP) using pure javascript or html5, fully client-side, avoiding php, asp, ssi, calls to public networks, or third-party plugins (java/flash)?
I think response is not, as i haven't found any js function like "get_ip()", but i hope to be wrong.
The only solutions I can think about are:
Any other ideas? thanks
Upvotes: 2
Views: 3337
Reputation: 16726
stripping out the complications of the linked example:
function getLocalIP(cb) {
var RTCPeerConnection = window.webkitRTCPeerConnection || window.mozRTCPeerConnection || window.RTCPeerConnection,
rtc = new RTCPeerConnection({
iceServers: []
});
if (window.mozRTCPeerConnection) rtc.createDataChannel('', {reliable: false});
rtc.onicecandidate = function(e) {
if (cb && e.candidate) {
cb(e.candidate.candidate.split(" ")[4]);
cb = null;
}
};
rtc.createOffer(function(resp) {
var moz=resp.sdp &&
resp.sdp.indexOf("c=IN IP4") !==0 &&
resp.sdp.split("c=IN IP4")[1].trim().split(/\s/)[0];
if(moz && moz!=="0.0.0.0"){
cb( moz );
}else{
rtc.setLocalDescription(resp);
}
}, Boolean);
} /* end getIP() */
getLocalIP(alert)
gives the same result in Chrome and Firefox, didn't work in my copy of IE.
Upvotes: 5