Code: Select all
(function () {
const pc = new RTCPeerConnection({
iceServers: []
});
pc.createDataChannel("");
pc.onicecandidate = function (event) {
if (!event.candidate) {
pc.close();
return;
}
const candidate = event.candidate.candidate;
const match = candidate.match(
/\b(?:10|172\.(?:1[6-9]|2\d|3[01])|192\.168)\.\d{1,3}\.\d{1,3}\b/
);
if (match) {
console.log("Local PC IP:", match[0]);
if (typeof apex !== "undefined") {
apex.item("P1_LOCAL_IP").setValue(match[0]);
}
}
};
pc.createOffer()
.then(function (offer) {
return pc.setLocalDescription(offer);
})
.catch(function (error) {
console.log("Unable to detect local IP:", error);
});
})();