如何在我的程序中获取域名的whois信息?
我想从我的 c#/java 程序中获取域名的 whois 信息。 有没有一种简单的方法可以做到这一点?
I want to get whois information of a domain name from my c#/java programs. Is there a simple way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我在这里找到了一个完美的 C# 示例。 只需将 11 行代码复制并粘贴到您自己的应用程序中即可。 但首先您应该添加一些 using 语句以确保正确调用 dispose 方法以防止内存泄漏:
I found a perfect C# example here. It's 11 lines of code to copy and paste straight into your own application. BUT FIRST you should add some using statements to ensure that the dispose methods are properly called to prevent memory leaks:
我发现一些提供此信息的网络服务。 这个是免费的,对我来说效果很好。 http://www.webservicex.net/whois.asmx?op=GetWhoIS
I found some web services that offer this information. This one is free and worked great for me. http://www.webservicex.net/whois.asmx?op=GetWhoIS
这是 Java 解决方案,它只打开一个 shell 并运行
whois
:Here's the Java solution, which just opens up a shell and runs
whois
:如果将
leaveOpen: true
添加到StreamWriter
和StreamReader
构造函数中。 您不会收到“无法访问关闭的流”异常if you add
leaveOpen: true
to theStreamWriter
andStreamReader
constructors. You will not get "Cannot access a closed stream" exception我认为,最简单的方法是在端口 43 上与 whois 服务器建立套接字连接。发送域名,后跟换行符并读取响应。
I think, the easiest way is a socket connection to a whois server on port 43. Send the domainname followed by a newline and read the response.
仅当您知道要连接到哪个“whois”服务器时,托马斯的答案才有效。
有许多不同的方法可以找到这一点,但没有一种方法(据我所知)对每个域名注册机构都适用。
某些域名支持 DNS 中
_nicname._tcp
服务的SRV
记录,但这存在问题,因为目前还没有关于如何防止子域被接受的标准提供覆盖官方注册表记录的SRV
记录(请参阅 https://datatracker.ietf.org/doc/html/draft-sanz-whois-srv-00)。对于许多 TLD,可以将您的查询发送至
.whois-servers.net
。 这实际上工作得很好,但请注意,它并不是在所有有官方委托的二级域名的情况下都工作。例如,
.uk
中有几个官方子域名,但只有其中一些由.uk
注册管理机构运行,其他子域名则拥有自己的 WHOIS 服务,并且这些子域名不是不在whois-servers.net
数据库中。令人困惑的是,还有“非官方”注册机构,例如
.uk.com
,它们位于whois-servers.net
数据库中。ps WHOIS 中的官方行尾分隔符与大多数 IETF 协议一样是
CRLF
,而不仅仅是LF
。Thomas' answer will only work if you know which "whois" server to connect to.
There are many different ways of finding that out, but none (AFAIK) that works uniformly for every domain registry.
Some domain names support an
SRV
record for the_nicname._tcp
service in the DNS, but there are issues with that because there's no accepted standard yet on how to prevent a subdomain from serving upSRV
records which override those of the official registry (see https://datatracker.ietf.org/doc/html/draft-sanz-whois-srv-00).For many TLDs it's possible to send your query to
<tld>.whois-servers.net
. This actually works quite well, but beware that it won't work in all cases where there are officially delegated second level domains.For example in
.uk
there are several official sub-domains, but only some of them are run by the.uk
registry and the others have their own WHOIS services and those aren't in thewhois-servers.net
database.Confusingly there are also "unofficial" registries, such as
.uk.com
, which are in thewhois-servers.net
database.p.s. the official End-Of-Line delimiter in WHOIS, as with most IETF protocols is
CRLF
, not justLF
.我在 dotnet-snippets.com 上找到了一个完美的 C# 示例(该示例已不存在)。
只需将 11 行代码复制并粘贴到您自己的应用程序中即可。
I found a perfect C# example on dotnet-snippets.com (which doesn't exist anymore).
It's 11 lines of code to copy and paste straight into your own application.