Call the domain name registration API to query all domain name combination scripts

Source: Internet
Author: User
Tags domain name registration

Today there is an idea, want to find out whether all the short domain name is registered, A-z1-9 composed of all 3, 4-bit combination of. com domain name has not been registered, so open dry, Google know that WAN provides an API can query, http://panda.www.net.cn/ Cgi-bin/check.cgi?area_domain=google.com, the back of the google.com can be changed to do you want to query the domain name, the result will return an XML page, as follows

<?xml version= "1.0" encoding= "gb2312"?><property><returncode>200</returncode><key> Google.com</key><original>211:domain name is not available</original></property>

The above is the domain name has been registered return page, the following is the domain name is not registered page, the code is 211,210

<?xml version= "1.0" encoding= "gb2312"?><property><returncode>200</returncode><key> Googleloveyou.com</key><original>210:domain name is available</original></property>

Domain Name Query API has, and then find a way to solve how to generate all the letters and numbers composed of 3,4,5 bit combination, this is difficult, generate all 3-bit combination, everyone is easy to solve, but the generation of 3,4,5 bit seems a little puzzled, Google did not get good information, so I draw, I think, And friends seeking ideas, finally solved, the idea is to use numbers instead of letters,

such as String = "abcdefghijklmnopqrstuvwxyz1234567890"

The resulting 4-bit domain name combination is aaaa aaab aaac aaad .... Aaba aabb ... Abaa abab etc., converted to numbers 0000 0001 0002 0003 respectively .... 0010 0011 ... 0100 0101 These numbers represent the index of the string, when the number is the letter length, the previous digit +1, and finally the list of numbers is converted to an alphabetical list, the script is as follows:

#!/usr/bin/python# coding: utf-8# author: guanghongwei# date: 2014/7/28#  mail:  time import urllibimport reapi =  "http://panda.www.net.cn/cgi-bin/ check.cgi?area_domain=%s "  # api address string = " abcdefghijklmnopqrstuvwxyz1234567890 "                     #  All Letters String_len = len (string)                                             #  length fname  =  ' Name.txt '                                                   #  not yet registered domain name written to the file suffix =  '. com '                                                       #  Domain suffix domain_lenth_ Range = range (3, 5)                                     #  the length of the letter combination, 3 to 5 but not including 5def min (num):     "" "Initializes the first value numeric List" "     name = []    for i in range (num):         name.append (0)     return name def  max (num, max_num):      "" "returns the maximum number of values in the list" ""     name =  []     For i in range (num):         name.append (max_num)      return name    def num_2_string (name, string):      "" To convert a list of numbers to a list of alphabetical combinations "" "    new_name = []     For i in name:        new_name.append (String[i])      return  ". Join (new_name)   def is_ava (domain):    " " Determine if the domain name is registered "" "    data = urllib.urlopen (Api % domain). Read ()      ava_pattern = re.compile (R ' <original> (. *)  : .*</original> ')     perm_pattern = re.compile (R ' Forbidden ')     result =  ava_pattern.findall (Data)     if  '  in result:        '  print  '%s ---------> ok '  % domain         return True    elif  ' 211 '  in result:         print  '%s ---------> no '  % domain         return False    else:         print  ' Forbidden '         return False         def domain_name (num):     "" "" "Domain Name Combination generator" "     name = min (num)     last = max (num, string _len-1)     while true:        yield num_ 2_string (name, string) &NBSP;&Nbsp;      if name == last:             break        name[num-1] +=  1        while string_len in name:             index = name.index (String_len)              name[index] = 0             name[index-1] += 1             def run (domain_lenth):     "" "executed, If each register is written to the file "" "    f = open (fname,  ' a ')     for  Domain in domain_name (domain_lenth):         domain +=  suffix    &Nbsp;   if is_ava (domain):             f.write ('%s\n '  % domain)              f.flush ()         time.sleep (0.5)       if __name__ ==  ' __main__ ':     "" "eventually executes,  loop to perform each length combination" ""      for i in domain_lenth_range:        run (i)

The script can be downloaded through the attachment, run directly, the results are as follows

650) this.width=650; "title=" 1.jpg "alt=" wkiol1pvwsegbm3oaagvrxs6dg0334.jpg "src=" http://s3.51cto.com/wyfs02/M02/ 41/6e/wkiol1pvwsegbm3oaagvrxs6dg0334.jpg "/>

Finally, because million network API, query too frequently, time interval is too short, will soon be sealed IP, pay attention to.

This article is from the "Free Linux, Share linux" blog, so be sure to keep this source http://laoguang.blog.51cto.com/6013350/1531198

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.