Search code examples
javascriptfirefox-addon

How to get the IP Adress in JS - Firefox Addon Devloment


I am building a small custom Firefox Addon with regards to the Firefox documentation. Basically it uses javascript and can also use some Firefox JS Extension APIs. I am trying to get the browser IP adress from inside the extension, usually I would use a PHP script for that but here I think I am limited to this HTML and JAVASCRIPT combination, Any ideas about this?


Solution

  •           var xmlhttp = new XMLHttpRequest();
          var url = "https://api.ipify.org/?format=json&callback=getIP";
    
      xmlhttp.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
          var myArr = JSON.parse(this.responseText);
          var ip = myArr.ip;
           console.log(ip);
          
        }
      };
      xmlhttp.open("GET", url, true);
      xmlhttp.send();
    

    you can use HTTP Request for Getting IP Add. of your client https://api.ipify.org this website provides you the user ip address as a json object