Using Apache Common's WhoisClient in Java

北城余情 提交于 2019-12-10 22:16:23

问题


I'm trying to do a WHOIS query with the WhoisClient object, and things aren't working out well. My code is pretty simple:

String WHOIS_SERVER = WhoisClient.DEFAULT_HOST;
int WHOIS_PORT = 43;
String hostName = "www.google.com";

WhoisClient whoisClient = new WhoisClient();
try
  {
  whoisClient.connect(WHOIS_SERVER, WHOIS_PORT);
  String results = whoisClient.query(hostName);

  return results;
  }
catch(IOException e)
  {
....            
  }

So a few things are wrong. I get the registrar information, but don't get the owner info. Also, there's lots of information about Google domains in other TLDs not just google.com.

I'm pretty sure I'm not specifying the host properly to get what I want. The documentation says:

It is up to the programmer to be familiar with the handle syntax of the whois server.

Not sure what that means. How can I do this better?


回答1:


Not completely sure what exactly you are looking to get back, but running the whois query from some of the web clients returned slightly different data. Wikipedia page had some info. So I changed the following line and got back some different results from using the default hostname.

whoisClient.connect("whois.iana.org", WHOIS_PORT);  // changed host name

Results:
% IANA WHOIS server % for more information on IANA, visit http://www.iana.org % This query returned 1 object

refer:        whois.verisign-grs.com

domain:       COM

organisation: VeriSign Global Registry Services
address:      12061 Bluemont Way
address:      Reston Virginia 20190
address:      United States

contact:      administrative
name:         Registry Customer Service
organisation: VeriSign Global Registry Services
address:      12061 Bluemont Way
address:      Reston Virginia 20190
address:      United States
phone:        +1 703 925-6999
fax-no:       +1 703 948 3978
e-mail:       info@verisign-grs.com

contact:      technical
name:         Registry Customer Service
organisation: VeriSign Global Registry Services
address:      12061 Bluemont Way
address:      Reston Virginia 20190
address:      United States
phone:        +1 703 925-6999
fax-no:       +1 703 948 3978
e-mail:       info@verisign-grs.com

nserver:      A.GTLD-SERVERS.NET 192.5.6.30 2001:503:a83e:0:0:0:2:30
nserver:      B.GTLD-SERVERS.NET 192.33.14.30 2001:503:231d:0:0:0:2:30
nserver:      C.GTLD-SERVERS.NET 192.26.92.30
nserver:      D.GTLD-SERVERS.NET 192.31.80.30
nserver:      E.GTLD-SERVERS.NET 192.12.94.30
nserver:      F.GTLD-SERVERS.NET 192.35.51.30
nserver:      G.GTLD-SERVERS.NET 192.42.93.30
nserver:      H.GTLD-SERVERS.NET 192.54.112.30
nserver:      I.GTLD-SERVERS.NET 192.43.172.30
nserver:      J.GTLD-SERVERS.NET 192.48.79.30
nserver:      K.GTLD-SERVERS.NET 192.52.178.30
nserver:      L.GTLD-SERVERS.NET 192.41.162.30
nserver:      M.GTLD-SERVERS.NET 192.55.83.30
ds-rdata:     30909 8 2 E2D3C916F6DEEAC73294E8268FB5885044A833FC5459588F4A9184CFC41A5766

whois:        whois.verisign-grs.com

status:       ACTIVE
remarks:      Registration information: http://www.verisign-grs.com

created:      1985-01-01
changed:      2012-02-15
source:       IANA


来源:https://stackoverflow.com/questions/21923598/using-apache-commons-whoisclient-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!