且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否可以检测访问者 DNS 服务器?

更新时间:2023-12-03 09:19:46

这并不容易,但可以做到.Adam Dobrawy 在 http://ipleak.net/

的单独回答中提出了该方法的演示>

要添加一些细节,您可以实现以下内容的方式是:

第 1 部分 - 在 myspecialdomain.com 上设置您自己的 DNS 服务器

需要自定义写入此 DNS 服务器以记录和存储传入请求和源 IP 地址.这种存储只需要很短的时间,所以像 memcache 这样的东西可能会很好地工作.DNS 响应应该是 NXDOMAIN.

第 2 部分 - 您的客户端代码

在您的 JavaScript 中制作并存储一个大的随机数.使浏览器查找 .myspecialdomain.com.通过带有错误处理程序的 JS img 标签加载它.在该错误处理程序中,现在对传递随机数的服务器端代码进行查询.

第 3 部分 - 您的 Web 应用程序(服务器端)

您需要实现一些服务器端逻辑,该逻辑采用随机字符串,在数据存储中查找,并检索 DNS 服务器的 IP 地址.注意这里的 IP 地址将是特定服务器的 IP 单播地址,它不会是像 8.8.8.8 这样的 IP Anycast 地址.在这里,您可以使用 GeoIP 或 Whois 数据库来确定该 IP 地址的所有者(OpenDNS、Google 等).然后,您可以生成响应以发送到客户端逻辑.

Detecting visitor IP is easy. But how about detecting DNS server ips of a visitor ?

I found this PHP function, however it finds only domain names' DNS.

dns_get_record("website.com", DNS_ANY);

Is it possible to detect visitor DNS server ?

It's not easy, but it can be done. There's a demonstration of the approach suggested in a separate answer by Adam Dobrawy at http://ipleak.net/

To add a bit of detail, the way you can implement something like this is:

Part 1 - Set up your own DNS server on myspecialdomain.com

This DNS server needs to be custom written to log and store the incoming request and the source IP address. This storage only needs to be for a short period of time, so something like memcache might work nicely. The DNS response should be an NXDOMAIN.

Part 2 - Your client-side code

In your Javscript make and store a large random number. Make the browser lookup .myspecialdomain.com. Load this via a JS img tag with an error handler. In that error handler, now make a query to your server side code passing the random number.

Part 3 - Your web application (server side)

You need to implement some server side logic that takes the random string, looks it up in the datastore, and retrieves the IP address of the DNS server. Note the IP address here will be the IP Unicast address of the particular server, it won't be an IP Anycast address like 8.8.8.8. Here you can use GeoIP or Whois databases to determine the owner of that IP address (OpenDNS, Google etc). You can then generate a response to send to the client logic.