Get client’s IP address using JavaScript

Javascript is unable to get the client IP, however, it is possible to retrieve it by making an ajax call to a service or web page that shows it to us. offers a free service with no limitations for this purpose. Just open this web page:

Here is an example in pure Javascript:

function getIpAddress() {
    var xmlhttp = new XMLHttpRequest();

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == XMLHttpRequest.DONE) {
            if (xmlhttp.status == 200) {
                alert("The IP address is: " + xmlhttp.responseText);

    };"GET", "", true);

Or with jQuery:

function getIpAddress() {
        url: '',
        success: function(data) {
            alert("The IP address is: " + data);

Leave a Comment

Your email address will not be published. Required fields are marked *