Обсуждения » Разработка

How to get ip address of the website I visit?

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.

§
Создано: 26.09.2022
Отредактировано: 26.09.2022

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);

§
Создано: 27.09.2022
Отредактировано: 27.09.2022

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.

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);

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.

Ответить

Войдите, чтобы ответить.