中文字幕在线一区二区在线,久久久精品免费观看国产,无码日日模日日碰夜夜爽,天堂av在线最新版在线,日韩美精品无码一本二本三本,麻豆精品三级国产国语,精品无码AⅤ片,国产区在线观看视频

      Java如何實現簡單的whois查詢

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

      Java如何實現簡單的whois查詢

        利用Java socket 實現根據IP地址查詢該IP相關的注冊信息。

        源代碼直接下載:java_whois.zip

        相關的兩個類WhoisBean.java 和WhoisQuery.java 代碼實現如下:

        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行數據

        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如何實現簡單的whois查詢】相關文章:

      Java byte[]轉int如何實現03-16

      實現鼠標畫圖的Java程序03-16

      Java多線程的實現方式03-20

      Java語言的特點和實現機制02-27

      Java動態代理實現AOP的方法03-16

      如何編譯java程序03-05

      java實現web服務器的方法03-30

      Java認證輔導:Java實現二叉樹遍歷算法03-19

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

      主站蜘蛛池模板: 太谷县| 在线观看精品国产福利片87| 久久精品综合国产二区| 国产亚洲日本人在线观看| 新疆| 免费的黄网站精品久久| 一级内射片在线网站观看视频| 午夜无码国产18禁| 大埔区| 一区二区三区福利在线视频| 手机AV片在线| 男人天堂av在线成人av| 清水河县| 惠水县| 一区二区三区内射视频在线观看| 亚洲精品中文字幕尤物综合| 中文字幕乱码中文乱码毛片| 97久久成人国产精品免费| 抚州市| 阿克苏市| 色琪琪一区二区三区亚洲区| 西西人体大胆视频无码| 国产成人香蕉久久久久| 窄裙美女教师在线观看视频| 99久久婷婷这里只有精品| 国产福利97精品一区二区| 余庆县| 炉霍县| 镇雄县| 连州市| 泗水县| 金湖县| 宁波市| 泰顺县| 久久久久国产精品四虎| 久久国产精品男人的天堂av| 车险| 亚洲国产精品久久久性色av| 一本色道久久综合亚洲精品蜜臀| 亚洲色图视频在线播放| 一区二区三区国产97|