亚洲一级电影在线观看,九九精品无码专区免费,亚洲AV无码资源在线观看 ,欧美国产高清

Java如何實現(xiàn)簡單的whois查詢

時間:2024-09-21 19:07:49 SUN認證 我要投稿
  • 相關推薦

Java如何實現(xiàn)簡單的whois查詢

  利用Java socket 實現(xiàn)根據(jù)IP地址查詢該IP相關的注冊信息。

  源代碼直接下載:java_whois.zip

  相關的兩個類WhoisBean.java 和WhoisQuery.java 代碼實現(xiàn)如下:

  Java代碼

  import java.util.LinkedHashMap;

  import java.util.List;

  import java.util.Map;

  import java.util.Map.Entry;

  /**

  *

  * @author Michael sun

  */

  public class WhoisQuery {

  /**

  *

  * @param ip

  */

  private void queryIpInfo(String ip) {

  Map map = new LinkedHashMap();

  try {

  WhoisBean bean = new WhoisBean();

  bean.setTimeout(0);

  // bean.setServer("whois.apnic.net");

  bean.setServer("whois.ripe.net");

  bean.queryInfoByIp(ip);

  List infoList = bean.getInfoList();

  String value = "";

  String key = "";

  for (String infoTmp : infoList) {

  String[] arr = infoTmp.split(":[ ]*");

  if (arr.length > 1) {

  key = arr[0];

  value = arr[1];

  } else {

  value = arr[0].trim();

  }

  if (null == map.get(key)) {

  map.put(key, "");

  }

  value = map.get(key) + value;

  map.put(key, value);

  }

  } catch (Exception e) {

  e.printStackTrace();

  }

  for (Entry entry : map.entrySet()) {

  System.out.println(entry.getKey() + ":" + entry.getValue());

  }

  }

  /**

  * @param args

  */

  public static void main(String[] args) {

  String ip = "129.42.58.216";// "163.1.13.189";

  WhoisQuery query = new WhoisQuery();

  query.queryIpInfo(ip);

  }

  }

  Java代碼

  import java.io.BufferedReader;

  import java.io.InputStreamReader;

  import java.io.PrintStream;

  import java.net.Socket;

  import java.util.ArrayList;

  import java.util.List;

  /**

  * WhoisBean

  * @author Michael sun

  */

  public class WhoisBean {

  /**

  * server address

  */

  private String server = "";

  /**

  * port

  */

  private int port = 43;

  /**

  * timeout/minute

  */

  private int timeout = 0;

  /**

  * infoList

  */

  private List infoList = new ArrayList();

  /**

  * @param ip

  * @throws Exception

  */

  @SuppressWarnings("unchecked")

  public void queryInfoByIp(String ip) throws Exception {

  Socket theSocket = null;

  BufferedReader br = null;

  PrintStream ps = null;

  int qryCount = 0;

  while (qryCount < 5) {

  qryCount++;

  try {

  theSocket = new Socket(server, port);

  theSocket.setSoTimeout(timeout * 1000);

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

  ps.println(ip);

  br = new BufferedReader(new InputStreamReader(theSocket

  .getInputStream()));

  infoList.add("ip:" + ip);

  String readLine = "";

  int i = 0;

  System.out.println("Whois query read start.... ");

  while ((readLine = br.readLine()) != null) {

  System.out.println("***" + readLine);

  if (readLine.length() > 0 && readLine.charAt(0) != '%') {

  infoList.add(readLine);

  i++;

  // 默認讀取100行數(shù)據(jù)

  if (i > 100 || readLine.startsWith("source")) {

  break;

  }

  }

  }

  System.out.println("querylist size:" + infoList.size());

  break;

  } catch (Exception e) {

  System.out.println("EXCEPTION : " + e);

  } finally {

  if (null != br) {

  br.close();

  }

  if (null != ps) {

  ps.close();

  }

  if (null != theSocket) {

  theSocket.close();

  }

  }

  }

  }

  /**

  * @return the server

  */

  public String getServer() {

  return server;

  }

  /**

  * @return the port

  */

  public int getPort() {

  return port;

  }

  /**

  * @return the timeout

  */

  public int getTimeout() {

  return timeout;

  }

  /**

  * @param pServer the server to set

  */

  public void setServer(String pServer) {

  server = pServer;

  }

  /**

  * @param pPort the port to set

  */

  public void setPort(int pPort) {

  port = pPort;

  }

  /**

  * @param pTimeout the timeout to set

  */

  public void setTimeout(int pTimeout) {

  timeout = pTimeout;

  }

  /**

  * @return the infoList

  */

  public List getInfoList() {

  return infoList;

  }

  /**

  * @param pInfoList the infoList to set

  */

  public void setInfoList(List pInfoList) {

  infoList = pInfoList;

  }

  }

  運行WhoisQuery這個類就可以看到如下信息:

  Java代碼

  Whois query read start....

  ***% This is the RIPE Database query service.

  ***% The objects are in RPSL format.

  ***%

  ***% The RIPE Database is subject to Terms and Conditions.

  ***% See http://www.ripe.net/db/support/db-terms-conditions.pdf

  ***

  ***% Note: This output has been filtered.

  ***% To receive output for a database update, use the "-B" flag.

  ***

  ***% Information related to '129.0.0.0 - 129.255.255.255'

  ***

  ***inetnum: 129.0.0.0 - 129.255.255.255

  ***netname: EU-ZZ-129

  ***descr: Various Registries

  ***country: EU # Country is really world wide

  ***remarks: These addresses were issued by

  *** The IANA before the formation of

  *** Regional Internet Registries.

  ***

  ***org: ORG-NCC1-RIPE

  ***admin-c: iana1-RIPE

  ***tech-c: iana1-RIPE

  ***status: ALLOCATED UNSPECIFIED

  ***mnt-by: RIPE-NCC-HM-MNT

  ***mnt-lower: RIPE-NCC-HM-MNT

  ***mnt-routes: RIPE-NCC-RPSL-MNT

  ***source: RIPE # Filtered

  querylist size:17

  ip:129.42.58.216

  inetnum:129.0.0.0 - 129.255.255.255

  netname:EU-ZZ-129

  descr:Various Registries

  country:EU # Country is really world wide

  remarks:These addresses were issued byThe IANA before the formation ofRegional Internet Registries.

  org:ORG-NCC1-RIPE

  admin-c:iana1-RIPE

  tech-c:iana1-RIPE

  status:ALLOCATED UNSPECIFIED

  mnt-by:RIPE-NCC-HM-MNT

  mnt-lower:RIPE-NCC-HM-MNT

  mnt-routes:RIPE-NCC-RPSL-MNT

  source:RIPE # Filtered

【Java如何實現(xiàn)簡單的whois查詢】相關文章:

Java byte[]轉(zhuǎn)int如何實現(xiàn)03-16

實現(xiàn)鼠標畫圖的Java程序03-16

Java多線程的實現(xiàn)方式03-20

Java語言的特點和實現(xiàn)機制02-27

Java動態(tài)代理實現(xiàn)AOP的方法03-16

如何編譯java程序03-05

java實現(xiàn)web服務器的方法03-30

Java認證輔導:Java實現(xiàn)二叉樹遍歷算法03-19

如何讓JAVA代碼更高效03-20

主站蜘蛛池模板: 亚洲仺av香蕉久久| 亚洲国产精品成人无码区| 在线观看91香蕉国产免费| 一级片一区| 日韩国产亚洲一区二区在线观看| 综合网天天| 视频二区精品中文字幕| 久久天堂av综合合色蜜桃网| 蜜臀久久99精品久久久久久小说| 国产亚洲精品一区二区三区| 日韩无套无码精品| 龙州县| 国产男女猛烈无遮挡免费视频 | 亚洲日本乱码一区二区在线二产线| 国产免费人成在线视频网站| 精品无码国产污污污免费网站国产 | 国产一级毛片高清完整视频版| 国产午夜无码专区喷水| 国产清纯在线一区二区vr| 国产超碰av人人做人人爽| 久久精品国产亚洲AV忘忧草18| 色丁狠狠桃花久久综合网| 午夜福利视频合集| 香蕉在线 亚洲 欧美 专区| 澎湖县| 久久乐国产精品亚洲综合| 亚洲一本到无码av中文字幕| 亚洲第一区无码专区| 国产精品自产拍在线观看中文| 综合激情丁香久久狠狠男同| 建昌县| 少妇高清一区二区免费看| 人妻体体内射精一区二区| 成人国产精品无码网站| 国产欧美日韩在线在线不卡视频| 国产亚洲精| 99久热re在线精品99 6热视频| 亚洲人色婷婷成人网站在线观看| 国产最新av在线播放不卡| 欧美三级视频| 女同国产精品一区二区|