Using Python to implement IP anti-search domain names

Source: Internet
Author: User

0x00

Take advantage of the summer Kungfu, the first time to learn Python, the biggest feeling is that this language is the best language I have ever seen. Especially its powerful class library and simple syntax.

I have nothing to do, today I write a small ip in Python to check the domain name tool.

IP counter-Search is the IP address of the reverse query the binding on this IP all the domain name information (a server can have more than one virtual host).

0x01

The idea is to use the Internet IP reverse search domain name site, here I use is http://dns.aizhan.com/. The query results are extracted from the Web page through a crawler and finally exported to an HTML file.

Use is also very convenient, such as you want to query the IP address is 10.10.10.10, then submit: http://dns.aizhan.com/?q=10.10.10.10 can.

However, the query results are not returned directly, but are dynamically obtained using AJAX. Then use Firebug to find the corresponding interface on the line.


The first URL is to get a total query result (JSON), the other URL is to get the title of the domain name. In this way, there are only two things to do:

The first is to extract all the URLs on this page from JSON.

The second is based on the list of URLs to find each URL corresponding to the title



The above image is a domain name corresponding to a title, just the two information as a data element can be.

0x03

With the above analysis basis, you can see my code directly.

#coding =utf-8 ' ' IP anti-search gadget http://dns.aizhan.com/index.php?r=index/domains&ip=202.203.208.8&page=1&_=  1408264478284 ' Import requests,json,urllib,sys,os from BS4 import BeautifulSoup #获取页面内容 def getpage (ip,page): R = 
Requests.get ("http://dns.aizhan.com/index.php?r=index/domains&ip=%s&page=%d"% (ip,page)) return R #获取最大的页数
    def getmaxpage (IP): R = GetPage (ip,1) json_data = {} Json_data = R.json () Maxcount = Json_data[u ' Conut '] maxpage = int (int (maxcount)/20) + 1 return maxpage #获取域名列表 def getdomainslist (IP): maxpage = GetMaxPage (i 
    p) result = [] for x in Xrange (1,maxpage+1): R = GetPage (ip,x) result.append (R.json () [U "domains"]) Return result #获取最终结果, in the form of: {URL title} and written to the file Def getresultwithtitle (filepath,domain_list): F = open (filepath, "a
        ") res_dict = {' domain ': ', ' title ': '} res_list = [] f.write ('  


0x04

The above code I have carried through, the effect is as follows:



It seems that making good use of Python can really solve a lot of problems easily.




Related Article

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.