Can I perform a DNS lookup (hostname to IP address) using client-side Javascript?

后端 未结 16 1774
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 11:45

I would like to use client-side Javascript to perform a DNS lookup (hostname to IP address) as seen from the client\'s computer. Is that possible?

16条回答
  •  清歌不尽
    2020-11-22 11:56

    As many people said you need to use an external service and call it. And that will only get you the DNS resolution from the server perspective.

    If that's good enough and if you just need DNS resolution you can use the following Docker container:

    https://github.com/kuralabs/docker-webaiodns

    Endpoints:

    [GET] /ipv6/[domain]: Perform a DNS resolution for given domain and return the associated IPv6 addresses.

     {
         "addresses": [
             "2a01:91ff::f03c:7e01:51bd:fe1f"
         ]
     }
    

    [GET] /ipv4/[domain]: Perform a DNS resolution for given domain and return the associated IPv4 addresses.

     {
         "addresses": [
             "139.180.232.162"
         ]
     }
    

    My recommendation is that you setup your web server to reverse proxy to the container on a particular endpoint in your server serving your Javascript and call it using your standard Javascript Ajax functions.

提交回复
热议问题