Is there a way to get the client's private IP address from the server or somehow pass it to it without it being hidden?
Currently I do it as follows:
var ipPrivada = "";
function obtenerIPJS(variable) {
// NOTE: window.RTCPeerConnection is "not a constructor" in FF22/23
var RTCPeerConnection = /*window.RTCPeerConnection ||*/ window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
if (RTCPeerConnection) (function () {
var rtc = new RTCPeerConnection({iceServers:[]});
if (1 || window.mozRTCPeerConnection) { // FF [and now Chrome!] needs a channel/stream to proceed
rtc.createDataChannel('', {reliable:false});
};
rtc.onicecandidate = function (evt) {
// convert the candidate to SDP so we can run it through our general parser
// see https://twitter.com/lancestout/status/525796175425720320 for details
if (evt.candidate) grepSDP("a="+evt.candidate.candidate, variable);
};
rtc.createOffer(function (offerDesc) {
grepSDP(offerDesc.sdp, variable);
rtc.setLocalDescription(offerDesc);
}, function (e) { console.warn("offer failed", e); });
function updateDisplay(newAddr, variable) {
var varConEval = eval(variable);
if (varConEval != "") varConEval = varConEval+",";
varConEval = varConEval+newAddr;
eval(variable+" = varConEval");
}
function grepSDP(sdp, variable) {
var hosts = [];
sdp.split('\r\n').forEach(function (line) { // c.f. http://tools.ietf.org/html/rfc4566#page-39
if (~line.indexOf("a=candidate")) { // http://tools.ietf.org/html/rfc4566#section-5.13
var parts = line.split(' '), // http://tools.ietf.org/html/rfc5245#section-15.1
addr = parts[4],
type = parts[7];
if (type === 'host') updateDisplay(addr, variable);
} else if (~line.indexOf("c=")) { // http://tools.ietf.org/html/rfc4566#section-5.7
var parts = line.split(' '),
addr = parts[2];
updateDisplay(addr, variable);
}
});
console.log("varIP"+eval(variable));
}
})(); else {
}
}
obtenerIPJS("ipPrivada");
The problem is that this worked before with another version of firefox/chrome (I don't know which one). Now these browsers by default hide the private local IP. And output it with a format like this: ej1k-18fa-loquesea.local
This option to hide the IP is something that can be changed with the #enable-webrtc-hide-local-ips-with-mdns
browser variable, but it is not an option.
Ideally, the user does not have to modify anything in the browser.
The IP is sent to the server to check if it is on the list of valid IPs to perform that action, so the question would be the one at the beginning:
Is there a way to get the client's private IP address from the server or somehow pass it to it without it being hidden?
Related but outdated: How to get the IP or hostname with JavaScript
No it can not be done.
Historically it has never been possible, it is simply a private data that you did not need to know.
When the WebRTC protocol was added, it was allowed to obtain that information in the first versions of the standard ... until they decided that it was a security problem that should be avoided and in the current versions it is requested to be hidden again.