/**
* @author 道生一
* @version 1.3
*/
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.Socket;
public class who {
/**
* 从NIC获取注册信息
*
* @param domain
* @return
*/
@SuppressWarnings("deprecation")
public static String getRegisterInfoAtNIC(String domain) {
final int port = 43;
final String host = getCheckHost(domain);
if(host == null){
System.err.println("错误,没有为该域名匹配到合法的查询主机!");
System.exit(1);
}
// System.err.println(host);
Socket theSocket = null;
// BufferedReader br = null;
PrintStream ps = null;
InputStream in = null;
StringBuffer sb = new StringBuffer();
String info = null;
if (host == null) {
return null;
}
try {
// 在TCP服务端口43(十进制)连接SRI-NIC服务主机
theSocket = new Socket(host, port, true);
ps = new PrintStream(theSocket.getOutputStream());
ps.print(domain + " ");
// 以回车和换行()结尾
ps.print("\r\n");
in = theSocket.getInputStream();
int ch;
while ((ch = in.read()) != -1) {
// Debug.dump(s);
sb.append((char) ch);
}
info = new String(sb.toString().getBytes("ISO-8859-1"), "UTF-8");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (Exception e) {
// e.printStackTrace();
// log.info(e);
}
try {
ps.close();
} catch (Exception e) {
// TODO 自动生成 catch 块
// e.printStackTrace();
// log.info(e);
}
try {
theSocket.close();
} catch (IOException e) {
// TODO 自动生成 catch 块
// e.printStackTrace();
// log.info(e);
}
}
return info;
}
/**
*
* @param domain
* @return
*/
private static String getCheckHost(String domain) {
String host = null;
String tld = getDomainTLD(domain);
if (tld.endsWith(".cn")) {
if (tld.equalsIgnoreCase(".edu.cn")) {
host = "whois.edu.cn";
} else {
host = "whois.cnnic.net.cn";
}
} else if (tld.equalsIgnoreCase(".com") || tld.equalsIgnoreCase(".net")
|| tld.equalsIgnoreCase(".edu")) {
host = "whois.internic.net";// 这里也可以是rs.internic.net
} else if (tld.equalsIgnoreCase(".org")) {
host = "whois.pir.org";
} else if (tld.equalsIgnoreCase(".info")) {
host = "whois.afilias.info";
} else if (tld.equalsIgnoreCase(".biz")) {
host = "whois.biz";
} else if (tld.equalsIgnoreCase(".cc") || tld.equalsIgnoreCase(".tv")
|| tld.equalsIgnoreCase(".jobs")) {
host = "whois.nic.cc";
} else if (tld.equalsIgnoreCase(".gov")) {
host = "whois.larc.nasa.gov";
} else if (tld.endsWith(".hk")) {
host = "whois.hkdnr.net.hk";
}
return host;
}
private static String getDomainTLD(String domain) {
return domain.substring(domain.indexOf("."));
}
public static void main(String[] args) {
//检查命令行参数
if (args.length < 1) {
System.out.println("\nUsage: java who ");
System.out.println("Parameters:");
System.out.println("Example:");
System.out.println("\tjava who sohu.com");
System.exit(1); // 退出
}
System.out.println(getRegisterInfoAtNIC(args[0]));
}
}
===================================================
使用示例:
E:\temp>java who test.cn
Domain Name: test.cn
ROID: 20030312s10001s00063170-cn
Domain Status: ok
Registrant Organization: 北京慧思德科技有限公司
Registrant Name: 安虎生
Administrative Email: info@wisdom.com.cn
Sponsoring Registrar: 北京新网数码信息技术有限公司
Name Server:dns2.wisdom.com.cn
Name Server:dns.wisdom.com.cn
Registration Date: 2003-03-17 12:20
Expiration Date: 2008-03-17 12:48
E:\temp>java who test.com
Whois Server Version 1.3
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.
TEST.COM.MY
TEST.COM.AU
TEST.COM
To single out one record, look it up with "xxx", where xxx is one of the
of the records displayed above. If the records are the same, look them up
with "=xxx" to receive a full display for each record.
>>> Last update of whois database: Sat, 26 May 2007 21:25:01 UTC <<<
NOTICE: The expiration date displayed in this record is the date the
registrar's sponsorship of the domain name registration in the registry is
currently set to expire. This date does not necessarily reflect the expiration
date of the domain name registrant's agreement with the sponsoring
registrar. Users may consult the sponsoring registrar's Whois database to
view the registrar's reported date of expiration for this registration.
TERMS OF USE: You are not authorized to access or query our Whois
database through the use of electronic processes that are high-volume and
automated except as reasonably necessary to register domain names or
modify existing registrations; the Data in VeriSign Global Registry
Services' ("VeriSign") Whois database is provided by VeriSign for
information purposes only, and to assist persons in obtaining information
about or related to a domain name registration record. VeriSign does not
guarantee its accuracy. By submitting a Whois query, you agree to abide
by the following terms of use: You agree that you may use this Data only
for lawful purposes and that under no circumstances will you use this Data
to: (1) allow, enable, or otherwise support the transmission of mass
unsolicited, commercial advertising or solicitations via e-mail, telephone,
or facsimile; or (2) enable high volume, automated, electronic processes
that apply to VeriSign (or its computer systems). The compilation,
repackaging, dissemination or other use of this Data is expressly
prohibited without the prior written consent of VeriSign. You agree not to
use electronic processes that are automated and high-volume to access or
query the Whois database except as reasonably necessary to register
domain names or modify existing registrations. VeriSign reserves the right
to restrict your access to the Whois database in its sole discretion to ensure
operational stability. VeriSign may restrict or terminate your access to the
Whois database for failure to abide by these terms of use. VeriSign
reserves the right to modify these terms at any time.
The Registry database contains ONLY .COM, .NET, .EDU domains and
Registrars.
E:\temp>java who test.net
Whois Server Version 1.3
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.
Domain Name: TEST.NET
Registrar: NETWORK SOLUTIONS, LLC.
Whois Server: whois.networksolutions.com
Referral URL: http://www.networksolutions.com
Name Server: NS1.MEDIATEMPLE.NET
Name Server: NS2.MEDIATEMPLE.NET
Status: clientTransferProhibited
Updated Date: 18-may-2007
Creation Date: 29-mar-1999
Expiration Date: 29-mar-2008
>>> Last update of whois database: Sat, 26 May 2007 21:25:01 UTC <<<
NOTICE: The expiration date displayed in this record is the date the
registrar's sponsorship of the domain name registration in the registry is
currently set to expire. This date does not necessarily reflect the expiration
date of the domain name registrant's agreement with the sponsoring
registrar. Users may consult the sponsoring registrar's Whois database to
view the registrar's reported date of expiration for this registration.
TERMS OF USE: You are not authorized to access or query our Whois
database through the use of electronic processes that are high-volume and
automated except as reasonably necessary to register domain names or
modify existing registrations; the Data in VeriSign Global Registry
Services' ("VeriSign") Whois database is provided by VeriSign for
information purposes only, and to assist persons in obtaining information
about or related to a domain name registration record. VeriSign does not
guarantee its accuracy. By submitting a Whois query, you agree to abide
by the following terms of use: You agree that you may use this Data only
for lawful purposes and that under no circumstances will you use this Data
to: (1) allow, enable, or otherwise support the transmission of mass
unsolicited, commercial advertising or solicitations via e-mail, telephone,
or facsimile; or (2) enable high volume, automated, electronic processes
that apply to VeriSign (or its computer systems). The compilation,
repackaging, dissemination or other use of this Data is expressly
prohibited without the prior written consent of VeriSign. You agree not to
use electronic processes that are automated and high-volume to access or
query the Whois database except as reasonably necessary to register
domain names or modify existing registrations. VeriSign reserves the right
to restrict your access to the Whois database in its sole discretion to ensure
operational stability. VeriSign may restrict or terminate your access to the
Whois database for failure to abide by these terms of use. VeriSign
reserves the right to modify these terms at any time.
The Registry database contains ONLY .COM, .NET, .EDU domains and
Registrars.
E:\temp>java who test.hk
-------------------------------------------------------------------------------
Whois server by HKDNR
-------------------------------------------------------------------------------
Domain names in the .com.hk, .net.hk, .edu.hk, .org.hk,
.gov.hk, idv.hk. and .hk can now be registered with HKDNR.
Go to http://www.hkdnr.net.hk for detail information.
-------------------------------------------------------------------------------
Domain Name: TEST.HK
Contract Version: HKDNR latest version
Registrant Contact Information:
Company English Name (It should be the same as the registered/corporation name o
n your Business Register Certificate or relevant documents): R&S COMPUTER SERVIC
ES COMPANY
Company Chinese name:
Address: Room 405, 4/F, Wah Chun Industrial Centre,
54 Tai Chung Road, Tsuen Wan, N.T.
Country: Hong Kong
Email: richard.so@datacap.com.hk
Domain Name Commencement Date: 27-05-2004
Expiry Date: 05-06-2008
Re-registration Status: Complete
Name of Registrar: HKDNR
Administrative Contact Information:
First name: Richard So
Last name:
Company name: R&S COMPUTER SERVICES COMPANY
Address: Room 405, 4/F, Wah Chun Industrial Centre,
54 Tai Chung Road, Tsuen Wan, N.T.
Country: Hong Kong
Phone: +852--21210868
Fax: +852--21210735
Email: richard.so@datacap.com.hk
Account Name: HK1499849T
Technical Contact Information:
First name: Richard So
Last name:
Company name: R&S COMPUTER SERVICES COMPANY
Address: Room 405, 4/F, Wah Chun Industrial Centre,
54 Tai Chung Road, Tsuen Wan, N.T.
Country: Hong Kong
Phone: +852--21210868
Fax: +852--21210735
Email: richard.so@datacap.com.hk
Name Servers Information:
DNS.TEST.HK
DNS1.KNOWLEDGE-SQUARE.COM
DNS2.KNOWLEDGE-SQUARE.COM
-------------------------------------------------------------------------------
The Registry contains ONLY .com.hk, .net.hk, .edu.hk, .org.hk,
.gov.hk, idv.hk. and .hk $domains.
-------------------------------------------------------------------------------
WHOIS Terms of Use
By using this WHOIS search enquiry service you agree to these terms of use.
The data in HKDNR's WHOIS search engine is for information purposes only and HKD
NR does not guarantee the accuracy of the data. The data is provided to assist p
eople to obtain information about the registration record of domain names regist
ered by HKDNR. You agree to use the data for lawful purposes only.
You are not authorised to use high-volume, electronic or automated processes to
access, query or harvest data from this WHOIS search enquiry service.
You agree that you will not and will not allow anyone else to:
a. use the data for mass unsolicited commercial advertising of any sort via a
ny medium including telephone, email or fax; or
b. enable high volume, automated or electronic processes that apply to HKDNR
or its computer systems including the WHOIS search enquiry service; or
c. without the prior written consent of HKDNR compile, repackage, disseminate
, disclose to any third party or use the data for a purpose other than obtaining
information about a domain name registration record; or
d. use such data to derive an economic benefit for yourself.
HKDNR in its sole discretion may terminate your access to the WHOIS search enqui
ry service (including, without limitation, blocking your IP address) at any time
including, without limitation, for excessive use of the WHOIS search enquiry se
rvice.
HKDNR may modify these terms of use at any time by publishing the modified terms
of use on its website.
E:\temp>java who test.cc
Whois Server Version 1.0
Domain names can now be registered with many different competing registrars.
Go to http://registrar.verisign-grs.com/whois/ for detailed information.
Domain Name: TEST.CC
Registrar: ENOM, INC.
Whois Server: whois.enom.com
Referral URL: http://www.enom.com
Name Server: NS2.GLOBALDNS.COM
Status: CLIENT-DELETE-PROHIBITED
Status: CLIENT-XFER-PROHIBITED
Updated Date: 13-dec-2006
Creation Date: 12-oct-1997
Expiration Date: 13-oct-2017
>>> Last update of whois database: Sun, 27 May 2007 08:03:38 EDT <<<
NOTICE: The expiration date displayed in this record is the date the
registrar's sponsorship of the domain name registration in the registry is
currently set to expire. This date does not necessarily reflect the
expiration date of the domain name registrant's agreement with the
sponsoring registrar. Users may consult the sponsoring registrar's
Whois database to view the registrar's reported date of expiration
for this registration.
TERMS OF USE: You are not authorized to access or query our Whois
database through the use of electronic processes that are high-volume and
automated except as reasonably necessary to register domain names or
modify existing registrations; the Data in VeriSign's ("VeriSign") Whois
database is provided by VeriSign for information purposes only, and to
assist persons in obtaining information about or related to a domain name
registration record. VeriSign does not guarantee its accuracy.
By submitting a Whois query, you agree to abide by the following terms of
use: You agree that you may use this Data only for lawful purposes and that
under no circumstances will you use this Data to: (1) allow, enable, or
otherwise support the transmission of mass unsolicited, commercial
advertising or solicitations via e-mail, telephone, or facsimile; or
(2) enable high volume, automated, electronic processes that apply to
VeriSign (or its computer systems). The compilation, repackaging,
dissemination or other use of this Data is expressly prohibited without
the prior written consent of VeriSign. You agree not to use electronic
processes that are automated and high-volume to access or query the
Whois database except as reasonably necessary to register domain names
or modify existing registrations. VeriSign reserves the right to restrict
your access to the Whois database in its sole discretion to ensure
operational stability. VeriSign may restrict or terminate your access to the
Whois database for failure to abide by these terms of use. VeriSign
reserves the right to modify these terms at any time.
The Registry database contains ONLY .cc, .tv, and .jobs domains
and Registrars.
===================================================================================
任何建议或意见请发送到邮箱aming8848@gmail.com或aming8848@126.com.
订阅:
博文评论 (Atom)
没有评论:
发表评论