Get the IP of the visited page?

Dear community,

I have recently tried to develop a add-on and wanted to know the visited URL & IP of the active tab.
(bootstraped add-on)

Therefore I have used the “tabs” extension and was able to get the URL.
But I am stuck to get the IP address, because I havn’t found a property for IP (like I did for url).

Is there a way to get the IP address too?
If you develop a plugin in chrome, you can get url & ip information together!

They workaroud to call an external URL (e.g. php) and get the IP this way isn’t sufficient, because of privacy reasons.

Thanks in advance :slightly_smiling:

EDIT:
Thanky you desktopd!
Your Post worked for me!

You will have to use a service that lets you the IP of the website. Like making an XHR request to this service - https://www.site24x7.com/find-ip-address-of-web-site.html

Or are you trying to get the IP of the user?

This seems to do the job.

const {Cc, Ci, Cu, components} = require ('chrome');
const dns = Cc['@mozilla.org/network/dns-service;1'].createInstance (Ci.nsIDNSService);
const thread = Cc['@mozilla.org/thread-manager;1'].getService (Ci.nsIThreadManager)
    .currentThread;

const host = 'www.mozilla.org';
(new Promise ((res, rej) => {
    dns.asyncResolve (host, 0, {
        onLookupComplete (req, record, status) {
            if (!components.isSuccessCode (status)) {
                // error
                rej ('Failed to resolve');
                return;
            }
        
            const addresses = [];
            try {
                while (true) {
                    const addr = record.getNextAddrAsString ();
                    if (!addr) break;
                    addresses.push (addr);
                }
            } finally {
                res (addresses);
            }
        }
    }, thread);
})).then (addr => {
    console.info ('resolved:', addr);
}).catch (e => {
    console.error (e);
});
2 Likes

Oh wow! Very very cool!