日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java 反查域名_C段查询雏形之在Java中反查一个IP上的所有域名(旁站查询)

發布時間:2025/3/13 java 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 反查域名_C段查询雏形之在Java中反查一个IP上的所有域名(旁站查询) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這里使用了兩個接口來反查IP,分別是“站長工具”和“愛站”的接口,兩者各有千秋,結合起來查詢就較為準確了。

注:我目前只寫了個初始版本,還不太完善,但是可以基本使用了,代碼中關鍵地方有注釋,所以我就不多解釋了

算法核心:package?NmapTest;

import?java.io.BufferedReader;

import?java.io.IOException;

import?java.io.InputStream;

import?java.io.InputStreamReader;

import?java.io.OutputStream;

import?java.net.HttpURLConnection;

import?java.net.MalformedURLException;

import?java.net.URL;

import?java.util.HashSet;

import?java.util.Set;

import?java.util.regex.Matcher;

import?java.util.regex.Pattern;

public?class?SearchDomainByIP?{

/**

*?IP反查(旁站查詢),綜合兩個接口的結果

*?@param?ip?待查IP

*

*?@return?返回結果集

*?*/

public?Set?getDomains(String?ip){

Set?set?=?new?HashSet();

set?=?getDomainByChinaz(searchDomainByChinaz(ip));??//chinaz接口

try?{

String[]?domainByAiZhan?=?searchDomainByAiZhan(ip,?1,?false).split("?");??//aizhan接口

for(String?s?:?domainByAiZhan){

if(!s.equals(""))

set.add(s);

}

}?catch?(IOException?e)?{

//?TODO?Auto-generated?catch?block

e.printStackTrace();

}

return?set;

}

/**

*?使用站長工具的接口,IP反查域名

*?@param?ip?待查IP

*

*?@return?返回包含結果的字符串

*?*/

private?String?searchDomainByChinaz(String?ip){

try?{

URL?url?=?new?URL("http://s.tool.chinaz.com/same");

HttpURLConnection?connection?=?(HttpURLConnection)?url.openConnection();

connection.setRequestMethod("POST");

connection.setRequestProperty("Content-Type",?"application/x-www-form-urlencoded");

connection.setDoInput(true);

connection.setDoOutput(true);

connection.setUseCaches(false);

String?str?=?"s="?+?ip;??//POST參數

OutputStream?outputStream?=?connection.getOutputStream();

outputStream.write(str.getBytes("UTF-8"));

outputStream.flush();??//開始請求

outputStream.close();

//返回數據包

if(connection.getResponseCode()?==?200){

InputStream?inputStream?=?connection.getInputStream();

BufferedReader?reader?=?new?BufferedReader(new?InputStreamReader(inputStream));

String?line?=?"";

String?reg?=?"\\s*

  • 1.(.*)?";??//匹配到目標行

    while((line?=?reader.readLine())?!=?null){

    if(line.matches(reg)){

    inputStream.close();

    reader.close();

    connection.disconnect();

    return?line.replaceFirst("\\s*

    • 1.",?"");??//返回包含目標的字符串

      }

      }

      }

      }?catch?(MalformedURLException?e)?{

      e.printStackTrace();

      }?catch?(IOException?e)?{

      e.printStackTrace();

      }

      return?"";

      }

      /**

      *?正則匹配出需要的一個個域名

      *?@param?data?包含所有結果的字符串

      *

      *?@return?目標域名的List集合

      *?*/

      private?Set?getDomainByChinaz(String?data){

      String?reg?=?"target=_blank>(.*?)

      ";??//準確匹配出查到的域名

    Pattern?pattern?=?Pattern.compile(reg);

    Matcher?matcher?=?pattern.matcher(data);

    Set?set?=?new?HashSet();

    while(matcher.find()){

    set.add(matcher.group(1));

    }

    return?set;

    }

    /**

    *?使用愛站網的接口,IP反查域名

    *?@param?ip?待查IP

    *?@param?currentPage?當前頁

    *?@param?checkNum?判斷域名總數是否已獲取

    *

    *?@return?返回包含結果的字符串

    *?@throws?IOException

    *?*/

    private?String?searchDomainByAiZhan(String?ip,int?currentPage,boolean?checkNum)?throws?IOException{

    URL?url?=?new?URL("http://dns.aizhan.com/"?+?ip?+?"/"?+?currentPage?+"/");

    HttpURLConnection?connection?=?(HttpURLConnection)?url.openConnection();

    connection.setRequestMethod("GET");

    connection.setConnectTimeout(10000);??//毫秒

    connection.setReadTimeout(10000);

    InputStream?inputStream?=?connection.getInputStream();

    BufferedReader?reader?=?new?BufferedReader(new?InputStreamReader(inputStream));

    String?line?=?"";

    String?numReg?=?"共有??(\\d*)??個域名解析到該IP";

    String?domainReg?=?"\\s*

    \\s*";??//匹配到目標行的上一行

    int?domainNumber?=?0;??//查到的域名總數

    String?domainNames?=?"";??//查到的所有域名的字符串集

    boolean?point?=?false;??//從false置為true時,表示已經找到目標行的上一行了,下一次循環即可取出目標行

    Pattern?pattern?=?Pattern.compile(numReg);

    Matcher?matcher?=?null;

    while((line?=?reader.readLine())?!=?null){

    //查域名總數

    if(!checkNum){

    matcher?=?pattern.matcher(line);

    if(matcher.find()){

    domainNumber?=?Integer.valueOf(matcher.group(1));

    checkNum?=?true;

    }

    }

    //查域名

    if(point){

    pattern?=?Pattern.compile("target=\"_blank\">(.*)?");

    matcher?=?pattern.matcher(line);

    if(matcher.find()){

    //System.out.println(matcher.group(1));

    domainNames?=?domainNames?+?matcher.group(1)?+?"?";

    point?=?false;

    }

    }

    else?if(line.matches(domainReg)){

    point?=?true;

    }

    }

    inputStream.close();

    reader.close();

    connection.disconnect();

    //如果當前頁下一頁還有內容,則進行遞歸調用查詢

    if(domainNumber?>?(20?*?currentPage)){

    try?{

    Thread.sleep(1000);??//線程休息1秒鐘

    }?catch?(InterruptedException?e)?{

    e.printStackTrace();

    }

    return?domainNames?+?searchDomainByAiZhan(ip,currentPage+1,true);

    }

    else{

    return?domainNames;

    }

    }

    }

    調用測試:package?NmapTest;

    import?java.util.HashSet;

    import?java.util.Iterator;

    import?java.util.Set;

    public?class?Domains?{

    /**

    *?@param?args

    */

    public?static?void?main(String[]?args)?{

    SearchDomainByIP?searchDomain?=?new?SearchDomainByIP();

    Set?set?=?new?HashSet();

    set?=?searchDomain.getDomains("162.211.183.152");

    Iterator?iterator?=?set.iterator();

    System.out.println("一共查到?"?+?set.size()?+?"個旁站");

    while(iterator.hasNext()){

    System.out.println(iterator.next());

    }

    }

    }

    輸出:

    一共查到 55個旁站

    www.anhao.ga

    www.3ga.cc

    www.xiaotwl.cn

    wapfeih.com

    www.52zyw.net

    lgdyw.pw

    xxin888.com

    www.hksf-expres.com

    www.zbhz.top

    yk666.cn

    www.mfdhw.cn

    danshenwl.com

    qq67.cn

    gjdc.cc

    www.5x2y0.com

    www.wz288.com

    wapzx.org

    85pj.cn

    www.txbk.cc

    yajie520.com

    www.wuyunzhu.top

    huanyan520.com

    lequk.com

    www.ddcd.net

    ail.so

    3pojie.com

    www.hacksg.com

    www.yin361.cn

    www.wapfeih.com

    xg-sfkd.com.cn

    www.xuexi47.cn

    www.huaxia47.com

    wz288.com

    www.sucaiziyuan.com

    wapsog.com

    qm6.cc

    www.58dh.cn

    hacksg.com

    zhuilixiang.com

    www.xhhzyw.com

    www.360360.pw

    www.495o.com

    surfs.cn

    shineky.cn

    www.danshenwl.com

    52daizi.com

    www.hei-tan.com

    xg-sfg.cn

    www.qqjudian.com

    sucaiziyuan.com

    moran.cc

    lghk.pw

    www.huanyan520.com

    hongbao.qq.com.mooyu.pub

    lexunc.com

    PS:通過IP反查域名本身就沒有確定的算法,因此有誤差再所難免。這也是我使用兩個不同接口來查詢的意義所在,可以互相彌補,使結果更加精確

    (PS:打個廣告,更多原創文章,盡在我的個人博客網站:http://www.zifangsky.cn)

總結

以上是生活随笔為你收集整理的java 反查域名_C段查询雏形之在Java中反查一个IP上的所有域名(旁站查询)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。