成人AV在线无码|婷婷五月激情色,|伊人加勒比二三四区|国产一区激情都市|亚洲AV无码电影|日av韩av无码|天堂在线亚洲Av|无码一区二区影院|成人无码毛片AV|超碰在线看中文字幕

WHOIS協(xié)議原理

Whois 協(xié)議原理及使用RFC812定義了一個非常簡單的Internet 信息查詢協(xié)議——WHOIS 協(xié)議。其基本內(nèi)容是,先向服務器的TCP 端口43建立一個連接,發(fā)送查詢關(guān)鍵字并加上回車換行,然后

Whois 協(xié)議原理及使用

RFC812定義了一個非常簡單的Internet 信息查詢協(xié)議——WHOIS 協(xié)議。其基本內(nèi)容是,先向服務器的TCP 端口43建立一個連接,發(fā)送查詢關(guān)鍵字并加上回車換行,然后接收服務器的查詢結(jié)果。

世界上各級Internet 管理機構(gòu)秉承公開、公正、共享的原則,設(shè)立了可以查知IP 地址和域名所有者登記資料的WHOIS 服務器,以便所有Internet 的使用者排除故障、打擊網(wǎng)上非法活動。全世界國際區(qū)域性的IP 地址管理機構(gòu)有四個:ARIN 、RIPE 、APNIC 、LACNIC ,他們負責的IP 地址的地理區(qū)域如下圖所示。

四個國際區(qū)域性IP 地址管理機構(gòu)所負責的區(qū)域

(此圖摘自《RIPE 2002年度報告》)

重要的Internet 管理機構(gòu)和常用的WHOIS 服務器

機構(gòu)縮寫 WHOIS 服務器地址 機構(gòu)全名及地點 提供查詢內(nèi)容

CERNIC whois.edu.cn 中國教育與科研計算機網(wǎng)網(wǎng)絡信息中心

(清華大學·中國北京) 中國教育網(wǎng)內(nèi)的IP 地址和.edu.cn 域名信息

CNNIC whois.cnnic.net.cn 中國互聯(lián)網(wǎng)絡信息中心

(中國科學院計算機網(wǎng)絡信息中心·中國北京) .cn 域名(除.edu.cn) 信息

INTERNIC whois.internic.net 互聯(lián)網(wǎng)絡信息中心

(美國洛杉磯市Marina del Rey鎮(zhèn)) .com,.net,.org,.biz,.info,.name

域名的注冊信息(只給出注冊代理公司)

ARIN whois.arin.net 美國Internet 號碼注冊中心

(美國弗吉尼亞州Chantilly 市) 全世界早期網(wǎng)絡及現(xiàn)在的美國、加拿大、撒哈拉沙漠以南非洲的IP 地址信息

APNIC whois.apnic.net 亞洲與太平洋地區(qū)網(wǎng)絡信息中心

(澳大利亞昆士蘭州密爾頓鎮(zhèn)) 東亞(包括中國大陸和臺灣) 、南亞、大洋洲IP 地址注信息 RIPE whois.ripe.net 歐州IP 地址注冊中心(荷蘭阿姆斯特丹) 歐洲、北非、西亞地區(qū)的IP 地址信息

TWNIC whois.twnic.net 臺灣互聯(lián)網(wǎng)絡信息中心(中國臺灣臺北) .tw 域名和部分臺灣島內(nèi)IP 地址信息

JPNIC whois.nic.ad.jp 日本互聯(lián)網(wǎng)絡信息中心(日本東京) .jp 域名和日本境內(nèi)的IP 地址信息

www.jianfeidongli.com

,

KRNIC whois.krnic.net 韓國互聯(lián)網(wǎng)絡信息中心(韓國漢城) .kr 域名和韓國境內(nèi)的IP 地址信息

LACNIC whois.lacnic.net 拉丁美洲及加勒比互聯(lián)網(wǎng)絡信息中心(巴西圣保羅) 拉丁美洲及加勒比海諸島IP 地址信息

本機上的自動WHOIS 服務,是按照下圖所示的流程,依次查詢?nèi)舾蓚€WHOIS 服務器之后,得到某個IP 地址的WHOIS 信息。

當我們準備建立一個Web 站點,就必須向域名登記機構(gòu)申請一個Internet 域名,因此,我們通常希望了解自己準備使用的域名是否已經(jīng)被注冊,這時,可以簡單地訪問InterNIC 站點http://www.internic.net/whois.html,在"Registry Whois" 輸入框中輸入需查詢的域名,就可以得到我們需要的結(jié)果。本文介紹了如何使用Java 編程來實現(xiàn)這個過程。

一 原理

原理非常簡單,域名的查詢主要是基于RFC 954提供的WHOIS 協(xié)議。在上述過程中,我們實際上是訪問了InterNIC 站點的WHOIS 服務器,該服務器從WHOIS 數(shù)據(jù)庫中查詢我們所需要的內(nèi)容。

WHOIS 服務器是一個基于" 查詢/響應" 的TCP 事務服務器,它運行在SRI-NIC 機器上(26.0.0.73或10.0.0.51) ,向用戶提供internet 范圍內(nèi)的目錄服務。本地主機上的用戶程序可以通過Internet 訪問該服務器,其過程主要有下面三步:

(1)在TCP 服務端口43(十進制) 連接SRI-NIC 服務主機;

(2)發(fā)送一個命令,以回車和換行()結(jié)尾;

(3)接受相應命令的返回信息,一旦輸出結(jié)束,服務器將關(guān)閉連接。

命令的格式非常簡單。可以直接輸入域名,例如,可以使用"sohu.com" 查詢" 搜狐" 網(wǎng)站的域名信息;也可以使用"help" 得到詳細的幫助信息。

二 Java socket編程簡述

在Java 中,使用Socket 類可以實現(xiàn)客戶端的sockets ,建立與服務器的網(wǎng)絡連接。本文www.jianfeidongli.com

,

使用下面所示的Socket 類的構(gòu)造器來創(chuàng)建一個流socket ,并連接到主機"whois.internic.net" 的端口43。

public Socket(String host, int port, boolean stream) throws IOException

其中,參數(shù)host 為遠程主機的主機名,port 為遠程主機的端口號,如果參數(shù)stream 為true ,則創(chuàng)建一個流socket ,否則創(chuàng)建一個數(shù)據(jù)報socket 。

如果創(chuàng)建socket 時發(fā)生I/O錯誤,將拋擲一個IOException 異常。

當創(chuàng)建了一個連接到遠程主機的socket 對象后,我們可以使用getInputStream()和getOutputStream()方法分別得到該socket 對象的輸入流和輸出流,用于對該socket 進行數(shù)據(jù)讀寫,為了使應用程序設(shè)計簡單,這些方法返回的流通常使用java.io 包中的實例對象來處理,例如:DataInputStream 和PrintWriter 。

從socket 讀數(shù)據(jù)使用readline()方法,一次讀取一行數(shù)據(jù)(字符串) :

public String readLine() throws IOException

向socket 寫數(shù)據(jù)使用print()方法:

public void print(String s)

當完成socket 通訊后,應該首先關(guān)閉DataInputStream 和PrintWriter 對象,最后才關(guān)閉socket 對象。

三 源程序

import java.net.*;

import java.io.*;

public class whois

{

public final static int port = 43;

public final static String hostname = "whois.internic.net";

public static void main(String[] args)

{

Socket theSocket;

DataInputStream theWhoisStream;

PrintStream ps;

//檢查命令行參數(shù)

if (args.length <1)

{

System.out.println("nUsage: java whois ");

System.out.println("Parameters:");

www.jianfeidongli.com

,

System.out.println(

"tcommand = one or more Domain name, or other command."); System.out.println("Example:");

System.out.println("tjava whois sohu.com");

System.out.println("tjava whois help");

System.exit(1); //退出

}

try {

//在TCP 服務端口43(十進制) 連接SRI-NIC 服務主機

theSocket = new Socket(hostname, port, true);

ps = new PrintStream(theSocket.getOutputStream());

//發(fā)送用戶提供的一個或多個命令

for (int i = 0; i < args.length; i )

ps.print(args[i] " ");

//以回車和換行()結(jié)尾

ps.print("rn");

//接受相應命令的返回信息

theWhoisStream = new DataInputStream(theSocket.getInputStream()); String s;

while ((s = theWhoisStream.readLine()) != null) {

System.out.println(s);

}

//關(guān)閉DataInputStream 和PrintWriter

theWhoisStream.close();

ps.close();

//關(guān)閉socket

theSocket.close();

}

catch (IOException e) {

System.err.println(e);

}

}

}

運行:java whois sina.com

運行結(jié)果:

Whois Server Version 2.0

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.

www.jianfeidongli.com

,

SINA.COM.CN

SINA.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: Tue, 03 Mar 2009 03:37:55 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.

www.jianfeidongli.com

標簽: