.NET:为什么这个域名无法解析?

发布于 2024-09-08 10:20:06 字数 1025 浏览 0 评论 0原文

我正在尝试以编程方式测试给定的域名是否存在。

以下代码行按预期工作:

IPHostEntry IPhst =Dns.GetHostEntry("google.com");

但对于同一主机上的某些域,它同时失败。例如,以下内容会引发异常。

IPHostEntry IPhst =Dns.GetHostEntry("bks-campus.ch");

生成的异常与域名根本不存在时引发的异常相同。

奇怪的是该域确实存在。我可以从刚刚运行上面代码的同一台机器上浏览它。

这里可能存在什么问题,我该如何解决这个问题?

编辑:Dig 也同意该域名确实存在:

dig bks-campus.ch

; <<>> DiG 9.5.0-P2 <<>> bks-campus.ch
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 14744
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;bks-campus.ch.                 IN      A

;; AUTHORITY SECTION:
bks-campus.ch.          3600    IN      SOA     dns1.bks-campus.ch. hostmaster.kanti-chur.ch. 1275546863 10800 3600 604800 86400

;; Query time: 1214 msec
;; SERVER: 192.168.0.1#53(192.168.0.1)
;; WHEN: Fri Jul  2 12:50:10 2010
;; MSG SIZE  rcvd: 94

I am trying to programmatically test if a given domain name exists.

The following line of code works as expected:

IPHostEntry IPhst =Dns.GetHostEntry("google.com");

But it fails for some few domains on the very same host at the very same time. For example, the following throws an exception.

IPHostEntry IPhst =Dns.GetHostEntry("bks-campus.ch");

The resulting exception is identical to exceptions that are thrown when the domain name does not exist at all.

The weird thing is that the domain actually exists. I am able to browse it from the same machine that just ran the code above.

What might be the problem here and how can I work around this?

Edit: Dig also agrees that this domain name actually exists:

dig bks-campus.ch

; <<>> DiG 9.5.0-P2 <<>> bks-campus.ch
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 14744
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;bks-campus.ch.                 IN      A

;; AUTHORITY SECTION:
bks-campus.ch.          3600    IN      SOA     dns1.bks-campus.ch. hostmaster.kanti-chur.ch. 1275546863 10800 3600 604800 86400

;; Query time: 1214 msec
;; SERVER: 192.168.0.1#53(192.168.0.1)
;; WHEN: Fri Jul  2 12:50:10 2010
;; MSG SIZE  rcvd: 94

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

去了角落 2024-09-15 10:20:06
; <<>> DiG 9.3.2 <<>> any bks-campus.ch @olympus
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1406
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;bks-campus.ch.                 IN      ANY

;; ANSWER SECTION:
bks-campus.ch.          86400   IN      SOA     dns1.bks-campus.ch. hostmaster.kanti-chur.ch. 1275546863 10800 3600 604800 86400
bks-campus.ch.          86400   IN      MX      20 cws02.netgrouper.ch.
bks-campus.ch.          86400   IN      MX      20 cws01.netgrouper.ch.
bks-campus.ch.          86400   IN      NS      dns1.bks-campus.ch.

;; AUTHORITY SECTION:
bks-campus.ch.          86400   IN      NS      dns1.bks-campus.ch.

;; ADDITIONAL SECTION:
cws02.netgrouper.ch.    32548   IN      A       194.150.160.32

;; Query time: 179 msec
;; SERVER: 192.168.2.4#53(192.168.2.4)
;; WHEN: Fri Jul 02 13:00:48 2010
;; MSG SIZE  rcvd: 193

bks-campus.ch 没有 A (IPv4) 记录,也没有任何 CNAME(别名)或 AAAA (IPv6)。响应仅告诉我们哪些服务器处理邮件 (MX)、dns (NS) 和一些管理记录 (SOA)。响应中没有任何内容告诉解析器在哪里可以找到 bks-campus.ch。添加A记录(或CNAME)就可以了。

; <<>> DiG 9.3.2 <<>> any bks-campus.ch @olympus
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1406
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;bks-campus.ch.                 IN      ANY

;; ANSWER SECTION:
bks-campus.ch.          86400   IN      SOA     dns1.bks-campus.ch. hostmaster.kanti-chur.ch. 1275546863 10800 3600 604800 86400
bks-campus.ch.          86400   IN      MX      20 cws02.netgrouper.ch.
bks-campus.ch.          86400   IN      MX      20 cws01.netgrouper.ch.
bks-campus.ch.          86400   IN      NS      dns1.bks-campus.ch.

;; AUTHORITY SECTION:
bks-campus.ch.          86400   IN      NS      dns1.bks-campus.ch.

;; ADDITIONAL SECTION:
cws02.netgrouper.ch.    32548   IN      A       194.150.160.32

;; Query time: 179 msec
;; SERVER: 192.168.2.4#53(192.168.2.4)
;; WHEN: Fri Jul 02 13:00:48 2010
;; MSG SIZE  rcvd: 193

There are no A (IPv4) records for bks-campus.ch, neither any CNAME (alias) or AAAA (IPv6). The response only tells us which servers handles mail (MX), dns (NS) and some administrative record (SOA). There's nothing in the response that tells the resolver where to find bks-campus.ch. Add an A record (or CNAME) and it will work.

╰沐子 2024-09-15 10:20:06

google.com 有一条将其与 IP 地址关联的 A 记录。 bks-campus.ch 没有任何 A、AAAA 或 CNAME 记录,因此您会收到错误消息。

当您的浏览器找不到该域的 A 记录时,它可能会自动添加 www。


编辑:您的 dig 输出确认 bks-campus.ch 存在,但没有 A 记录。

google.com has an A record associating it with an IP address. bks-campus.ch does not have any A, AAAA or CNAME records, so you get an error.

Your browser is probably automatically adding the www when it can't find an A record for the domain.


Edit: Your dig output confirms that bks-campus.ch exists but has no A record.

醉态萌生 2024-09-15 10:20:06

bks-campus.ch 没有 DNS 条目。浏览器可能会翻译为 www.bks-campus.ch,它有一个 DNS 条目,并且可能也可以通过代码运行。

编辑:域名存在,但您的 DNS 可能不知道。我的不知道,但它知道www.bks-campus.ch

bks-campus.ch doesn not have a DNS entry. Probably the browser translates to www.bks-campus.ch, which has a DNS entry, and would probably work from the code too.

EDIT: The domain name exists, but your DNS probably doesn't know it. Mine doesn't, but it knows www.bks-campus.ch.

奈何桥上唱咆哮 2024-09-15 10:20:06

您尝试通过代码执行的操作是查看域是否具有 bks-campus.ch 的解析 dns A 记录。您想要做的是请求域的 SOA 记录。请参阅此搜索 MX 记录的 CodeProject 项目。只需将记录类型更改为 SOA

这仅在域已委托给名称服务器时才有效。有些域已注册但未指向 DNS 服务器。在这些情况下,如果您在浏览器中输入域名,您只会收到一条错误消息。

查明域名是否已注册的最佳方法是进行 WHOIS 查找。这些由 TLD 注册管理机构运营,允许人们检查谁注册了域名。如果您远程登录到 whois.nic.coop 的端口 43 并输入域名“nosuchdomain.coop”,您将获得注册该域的详细信息。

.coop registry WHOIS server

For help on using this server use "?" (without the quotes).
For more .coop information browse to http://www.coop

nosuchdomain.coop
No domain records were found to match "nosuchdomain.coop"

--------------------------------------------------------------------------------

The .coop registry WHOIS database provides information for .coop registered
names only. Although every effort is made to maintain the accuracy of the WHOIS
data, accuracy cannot be guaranteed.

This service is intended only for query-based access. You agree that you will
use this data only for lawful purposes and that, under no circumstances will you
use this data to: (a) allow, enable, or otherwise support the transmission by
e-mail, telephone, or facsimile of mass unsolicited, commercial advertising or
solicitations to entities other than the data recipient's own existing
customers; or (b) enable high volume, automated, electronic processes that send
queries or data to the systems of Registry Operator or any ICANN-Accredited
Registrar, except as reasonably necessary to register domain names or modify
existing registrations. The compilation, repackaging, dissemination or other use
of this Data is expressly prohibited without the prior written consent of
dotCoop. All rights reserved. dotCoop reserves the right to modify these terms
at any time. By submitting this query, you agree to abide by this policy.

BY USING THE WHOIS SERVICE AND THE DATA CONTAINED HEREIN OR IN ANY REPORT
GENERATED WITH RESPECT THERETO, IT IS ACCEPTED THAT DOTCOOP IS NOT LIABLE FOR
ANY DAMAGES OF ANY KIND ARISING OUT OF, OR IN CONNECTION WITH, THE REPORT OR THE
INFORMATION PROVIDED BY THE WHOIS SERVICE, NOR OMISSIONS OR MISSING INFORMATION.
THE RESULTS OF ANY WHOIS REPORT OR INFORMATION PROVIDED BY THE WHOIS SERVICE
CANNOT BE RELIED UPON IN CONTEMPLATION OF LEGAL PROCEEDINGS WITHOUT FURTHER
VERIFICATION, NOR DO SUCH RESULTS CONSTITUTE A LEGAL OPINION.

如果您在正确的服务器上打开到此端口的套接字并向其发送域,捕获响应,然后解析该响应以查看 WHOIS 服务器是否报告该域是否已注册。

What you are trying to do by your code is to see if the domain has a resolving dns A record for bks-campus.ch. What you want to do is request the SOA record for a domain. see this CodeProject project that searches for the MX record. Just change the type of record to SOA

This will only work if the domain has been delegated to a name server. There are some domains that have been registered and just not pointed to a DNS server. In these cases you will just get an error message if you enter the domain name into a browser.

The BEST way to find out if a domain has been registered is to do a WHOIS lookup. These are run by the TLD Registries to allow people to check who has registered a domain name. If you telnet to port 43 of whois.nic.coop and type in a domain name "nosuchdomain.coop" you will get the details of who registered that domain.

.coop registry WHOIS server

For help on using this server use "?" (without the quotes).
For more .coop information browse to http://www.coop

nosuchdomain.coop
No domain records were found to match "nosuchdomain.coop"

--------------------------------------------------------------------------------

The .coop registry WHOIS database provides information for .coop registered
names only. Although every effort is made to maintain the accuracy of the WHOIS
data, accuracy cannot be guaranteed.

This service is intended only for query-based access. You agree that you will
use this data only for lawful purposes and that, under no circumstances will you
use this data to: (a) allow, enable, or otherwise support the transmission by
e-mail, telephone, or facsimile of mass unsolicited, commercial advertising or
solicitations to entities other than the data recipient's own existing
customers; or (b) enable high volume, automated, electronic processes that send
queries or data to the systems of Registry Operator or any ICANN-Accredited
Registrar, except as reasonably necessary to register domain names or modify
existing registrations. The compilation, repackaging, dissemination or other use
of this Data is expressly prohibited without the prior written consent of
dotCoop. All rights reserved. dotCoop reserves the right to modify these terms
at any time. By submitting this query, you agree to abide by this policy.

BY USING THE WHOIS SERVICE AND THE DATA CONTAINED HEREIN OR IN ANY REPORT
GENERATED WITH RESPECT THERETO, IT IS ACCEPTED THAT DOTCOOP IS NOT LIABLE FOR
ANY DAMAGES OF ANY KIND ARISING OUT OF, OR IN CONNECTION WITH, THE REPORT OR THE
INFORMATION PROVIDED BY THE WHOIS SERVICE, NOR OMISSIONS OR MISSING INFORMATION.
THE RESULTS OF ANY WHOIS REPORT OR INFORMATION PROVIDED BY THE WHOIS SERVICE
CANNOT BE RELIED UPON IN CONTEMPLATION OF LEGAL PROCEEDINGS WITHOUT FURTHER
VERIFICATION, NOR DO SUCH RESULTS CONSTITUTE A LEGAL OPINION.

If you open a socket to this port on the correct server and just send them the domain, capture the response, and then parse this to see if the WHOIS server reports if the domain is registered or not.

自此以后,行同陌路 2024-09-15 10:20:06

查看给定域是否存在的另一种方法是对相关域进行 NS 查找。如果域存在,则即使该域的注册名称服务器超时,它也必须有 NS 记录。

Another way to see if a given domain exists is to do a NS lookup for the domain in question. If the domain exists, it must have a NS record, even if the registered nameservers for the domain time out.

伪心 2024-09-15 10:20:06

尝试将网络适配器的DNS服务器设置为4.2.2.24.2.2.3。大多数情况下,如果我没记错的话,这会起作用,因为有时 ISP 的 DNS 服务器不会及时响应。在评论中让我知道你的结果。

Try setting the DNS servers for your NETWORK ADAPTER to 4.2.2.2 or 4.2.2.3. Mostly If I'm not mistaken this would work because sometimes DNS servers of ISPs don't respond timely. Let me know your results in comments.

风渺 2024-09-15 10:20:06

想到的原因有很多,但最有可能的是您的 DNS 基础设施未设置为解析此域。

请记住,即使您可以从网络浏览器浏览它,但如果您也通过网络代理,它也无法告诉您太多信息。它只是告诉您代理可以解析主机,而不是您的本地计算机。

最简单的方法是从命令行尝试 nslookup

nslookup bks-campus.ch

如果失败,则表明您的计算机使用的 DNS 无法解析此问题,因此您的代码无法解决此问题。

如果通过,则需要进行更多调查。回帖更多信息:)

Lots of reasons spring to mind but the most likely is that your DNS infrastructure is not set up to resolve this domain.

Bear in mind that even if you can browse to it from a web browser, it doesn't tell you much if you are also going through a web proxy. It just tells you the proxy can resolve the host, not your local machine.

The easiest way is to try nslookup from the command line

nslookup bks-campus.ch

If this fails, the DNS your machine is using cannot resolve this, so there is no way your code can.

If this passes, then more investigation is required. Post back more info :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文