Greasy Fork is available in English.

Discussions » Development

How to get ip address of the website I visit?

§
Posted: 2022.09.26.

How to get ip address of the website I visit with js, not from the devtool of Chrome?

I want to get the IP my browser use, not the one queried from online tools, because the result they return is sometimes different from what my browser use.

§
Posted: 2022.09.26.
Edited: 2022.09.26.

Fetch api.ipify.org to get your public ip address, or use these other APIs that shows more info https://api.db-ip.com/v2/free/self https://ipapi.co/json/

To get your local ip address seems like you would have to use window.RTCPeerConnection, but nothing I found work. Now browsers have higher security measures that seems to prevent this for some reason.

To do a dns lookup on the website and get the website server ip address use
var response = await fetch('https://dns.google/resolve?name=example.com');
var json = await response.json();
console.log('This website server IP Address is: ' + json.Answer[0].data);

§
Posted: 2022.09.27.
Edited: 2022.09.27.

Thank you for the help. I want to get the ip of the website I visit, namely the server, not the client.

After more search, I find it impossible to get the server IP the browser is using with js, but chrome extension can get it with API.

§
Posted: 2022.09.27.

To get the ip of the website you visit, namely the server, not the client use

var response = await fetch('https://dns.google/resolve?name=example.com');
var json = await response.json();
console.log('This website server IP Address is: ' + json.Answer[0].data);

§
Posted: 2022.09.27.

The reponse returned from web dns service or dns over https is sometimes different from the IP the browser use, for that DNS servers response based on where the request are from, and some websites have multiple IP in one A records.

Post reply

Sign in to post a reply.