Retrieving Local IP Address using Javascript or HTML5

To specify the custom data type for column index 4, use the mentioned value in the option. Additionally, you can retrieve the value through Ajax, utilizing xhr if it’s on your domain or DSL if there is a service that offers IPs in JSON format.


Solution:

Simplifying the intricacies of the given instance.

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)

The outcome obtained in Chrome and Firefox was not replicated in my IE browser.

Frequently Asked Questions