C-Segment query prototype in Java to check all domain names on an IP (side-station query)

Source: Internet
Author: User

Here used two interfaces to reverse IP, respectively, "Webmaster Tools" and "Love Station" interface, the two are different, combined with the query is more accurate.

Note: I currently only write an initial version, is not perfect, but can be used basically, the key place in the code has comments, so I do not explain 650) this.width=650; "Src=" http://www.zifangsky.cn/ Wp-content/plugins/kindeditor-for-wordpress/plugins/emoticons/images/73.gif "border=" 0 "style=" border:0px; Vertical-align:middle;height:auto; "/>

Algorithm Core:

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 Counter-search (side-station query), combined with the results of two interfaces  *  @param  ip  unknown origin ip *  *  @return   return result set  * */public  Set<string> getdomains (STRING&NBSP;IP) {set<string> set = new hashset< String> (); Set = getdomainbychinaz (Searchdomainbychinaz (IP));   //chinaz interface try { String[] domainbyaizhan = searchdomainbyaizhan (Ip, 1, false). Split (" ");   //aizhan interface for (String s : domainbyaizhan){if (!s.equals (")) Set.add (s);}}  catch  (ioexception e)  {// TODO Auto-generated catch  Blocke.printstacktrace ();} Return set;} /** *  use webmaster Tools interface, IP reverse domain name  *  @param  ip  unknown origin ip *  *  @return   Returns the string containing the result  * */private string searchdomainbychinaz (STRING&NBSP;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 parameter outputstream outputstream =  connection.getoutputstream (); Outputstream.write (Str.getbytes ("UTF-8")); Outputstream.flush ();   Start request Outputstream.close ();//Return packet if (cOnnection.getresponsecode ()  == 200) {inputstream inputstream =  Connection.getinputstream (); Bufferedreader reader = new bufferedreader (New inputstreamreader (InputStream)); string line =  ""; string reg =  "\\s*<ul><li><span>1.</span> (. *)?";   //matches to Target line while ((Line = reader.readline ())  != null) {if (Line.matches (reg)) { Inputstream.close (); Reader.close (); Connection.disconnect (); Return line.replacefirst ("\\s*<ul><li ><span>1.</span> ", ");   //returns the string containing the target}}}} catch  (malformedurlexception  e)  {e.printstacktrace ();}  catch  (ioexception e)  {e.printstacktrace ();} return  "";} /** *  matches the required domain name  *  @param  data  String that contains all the results  *  *  @return   Target domain's list collection  * */private set<string> getdomainbychinaz (string data) {String  reg =  "target=_blank> (. *?) </a></li> ";   //accurately matches the domain name Pattern pattern = pattern.compile (reg) found; Matcher matcher = pattern.matcher (data); Set<string> set = new hashset<string> (); while (Matcher.find ()) {Set.add ( Matcher.group (1));} Return set;} /** *  use the interface of AI station network, IP reverse domain name  *  @param  ip  unknown origin ip *  @param  currentPage  Current page  *  @param  checkNum  determine if the total number of domain names has been obtained  *  *  @return   returns the string containing the result  *   @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);   //msec connection.setreadtimeout (10000); Inputstream inputstream  = connection.getinputstream (); Bufferedreader reader = new bufferedreader (New inputstreamreader (InputStream)); string line =  ""; string numreg =  "Total   <font color=\" #FF0000 \ " id=\" Yhide\ "> (\\d*)?< /font>  a domain name resolves to the IP "; string domainreg =  "\\s*<td class=\" dns-links\ ">\\s*";   //matches the previous line int to the target row  domainnumber = 0;  //The total number of domain names found string domainnames =  "";   // The string set of all the domain names found boolean point = false;  //from False to True indicates that the previous row of the target row has been located, The target line Pattern pattern = pattern.compile (Numreg) can be removed in the next loop. Matcher matcher = null;while ((Line = reader.readline ())  != null) {//Check the total number of domains if ( !checknum) {matcher = pattern.matcher (line); if (Matcher.find ()) {DOMAINNUMBER&NBSP;=&NBSp;integer.valueof (Matcher.group (1)); checknum = true;}} Check the domain name if (point) {pattern = pattern.compile ("target=\" _blank\ "> (. *)?</a>"); matcher =  pattern.matcher (line), if (Matcher.find ()) {//system.out.println (Matcher.group (1));d omainnames =  Domainnames + matcher.group (1)  +  " ";  point = false;} Else if (Line.matches (Domainreg)) {point = true;}} Inputstream.close (); Reader.close (); Connection.disconnect ();//If there is content on the next page of the current page, make a recursive call to query if (domainnumber >   (20 * currentpage)) {try {thread.sleep (+);   //thread rest for 1 seconds} catch  ( interruptedexception e)  {e.printstacktrace ();} Return domainnames + searchdomainbyaizhan (ip,currentpage+1,true);} Else{return domainnames;}}}

To invoke the test:

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<string> set = new Hashset<string> (); set = Searchdomain.getdomains ("162.211.183.152");iterator< String> iterator = Set.iterator (); SYSTEM.OUT.PRINTLN ("total found" + set.size () + "Next Station"), while (Iterator.hasnext ()) {System.out.println (Iterator.next ());}}}

Output:

We found 55 side stations.
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: The IP counter-check domain name itself is not determined by the algorithm, so there is no longer inevitable error. This is what I use two different interfaces to query the meaning, can compensate each other, make the results more accurate

(PS: Make an advertisement, more original article, in my personal blog site: http://www.zifangsky.cn)

This article is from "Zifangsky's personal blog" blog, make sure to keep this source http://983836259.blog.51cto.com/7311475/1719263

C-Segment query prototype in Java to check all domain names on an IP (side-station query)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.