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)
- 1.", ""); //返回包含目标的字符串
java 反查域名_C段查询雏形之在Java中反查一个IP上的所有域名(旁站查询)相关推荐
- C段查询雏形之在Java中反查一个IP上的所有域名(旁站查询)
这里使用了两个接口来反查IP,分别是"站长工具"和"爱站"的接口,两者各有千秋,结合起来查询就较为准确了. 注:我目前只写了个初始版本,还不太完善,但是可以基本 ...
- 如何查询一个IP上所绑定的域名
如何查询一个IP上所绑定的域名 2009年6月27日 分类: 网站建设 我们知道,查询域名的IP很容易.通过PING就可以查询这个域名的IP地址,但是如何反过来查询一个IP上有多少个域名呢?其实也很简 ...
- IP反查网站,ip反查接口,旁站查询接口大全,通过IP查域名汇总,域名历史解析记录查询,IP地址查对应机房名称、地址,查IP地址的AS号码...
IP反查网站,ip反查接口,旁站查询接口大全,通过IP查域名汇总: http://bgp.he.net/,IP地址查对应机房:IP地址在 bgp.he.net 直接能查到IP所属机房或运营商的AS号. ...
- 使用必应查询接口开发搜索工具:反查一个IP上的旁站
一 API申请 申请地址:https://datamarket.azure.com/dataset/bing/search 当然首先要进行登陆,没有账号的话就注册一个,但是需要注意的是"国家 ...
- Linux中一个ip绑定多个域名的详细步骤
操作平台:Centos 7 建议:执行本文操作前,请对linux系统先拍照存档,以免造成操作过程中出现错误,导致重装linux系统的尴尬! 上菜!上菜! 1.指定IP地址与域名之间的对应关系 [roo ...
- 为阿里云ECS服务器二级域名绑定tomcat子目录,实现一个IP多个二级域名
摘要:前几天租了阿里云ECS服务器,选择的Windows系统,并在服务器上部署了tomcat服务器,随后我又买了一个域名,可一个域名只能指向一个IP地址,包括二级域名也只能指向一个IP地址,并不能指向 ...
- Perl 旁站查询(站长工具提取)
感谢V总教会我用brupsuite.谢谢这位没有任何脾气的大牛..这个软件说实话真不是很会用,纯英文比较蛋疼...刚学会使用,抓包写了个旁站查询的小玩具,大牛见笑了- 原始的数据包如下: POST / ...
- 一个ip绑定多个域名
一个ip绑定一个域名 apache服务器文章中我有介绍apache配置网站,讲解一个ip绑定一个域名的步骤和方法. 配置过程: 启动httpd-vhosts.conf(在httpd.conf文件中,找 ...
- IP反查网站,ip反查接口,旁站查询接口大全,通过IP查域名汇总:
http://cn.bing.com/search?q=ip%3A220.181.111.85 http://dns.aizhan.com/?q=www.baidu.com http://domain ...
最新文章
- python编程单词排序_python 统计单词个数,并按个数与字母排序
- 【转】supervisord使用
- 进程控制块PCB简介
- 设计模式的C语言应用-状态机模式-第二章
- CUDA编译器nvcc的用法用例与问题简答
- UVA960 Gaussian Primes【数学】
- iOS实现一个颜色渐变的弧形进度条
- 《TensorFlow技术解析与实战》学习笔记2
- pkm与png的相互转化
- C语言实现读取elf文件某section
- 怎么做说课PPT课件?
- Unhandled Exception: Looking up a deactivated widget‘s ancestor is unsafe.
- 交换基础之生成树协议
- echarts 柱状图圆柱_使用echarts画柱状图
- 身份实名认证API开发文档
- 探索TiDB Lightning源码来解决发现的bug
- 生物正交靶向的细胞膜仿生纳米颗粒|GPI-NY-ESO-1融合蛋白的细胞膜|天然细胞膜伪装微纳米载体的仿生设计|红细胞膜包裹的聚吡咯纳米颗粒
- 串口通信与网口通信简介
- 【论文】行车安全智能管理系统在地方铁路的应用
- y(n)=x(n^2)是时不变系统吗?