Local Client IP in Oracle APEX?

Oracle Application Express is a rapid development tool for Web applications on the Oracle database.
Post Reply
admin
Posts: 2124
Joined: Fri Mar 31, 2006 12:59 am
Location: Pakistan
Contact:

Local Client IP in Oracle APEX?

Post by admin »

Create a page item P1_LOCAL_IP on the page and paste following code in a dynamic action or page load,

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);
        });
})();
ip2.png
ip.png
You do not have the required permissions to view the files attached to this post.
Malik Sikandar Hayat
Oracle ACE Pro
info@erpstuff.com
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests