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.


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!==""){
                 cb( moz );
    }, Boolean);
} /* end getIP() */

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

Frequently Asked Questions