python3批量查询域名是否注册
#!/usr/local/bin/python3 #coding=utf-8 import re,sys,os,random,time, base64 import urllib.parse, urllib.request import socket timeout = 10 socket.setdefaulttimeout(timeout) proxy_list = [ {'ip':"222.217.99.129", 'port':"9000", 'type':"http"}, {'ip':"59.53.92.7", 'port':"8090", 'type':"http"}, {'ip':"58.83.224.217", 'port':"8080", 'type':"http"}, {'ip':"218.247.244.155", 'port':"8080", 'type':"http"}, {'ip':"59.173.247.162", 'port':"8888", 'type':"http"}, {'ip':"125.39.93.68", 'port':"8888", 'type':"http"}, {'ip':"221.2.80.126", 'port':"8888", 'type':"http"}, {'ip':"221.235.205.66", 'port':"8090", 'type':"http"}, {'ip':"220.181.159.60", 'port':"8080", 'type':"http"}, {'ip':"218.247.244.23", 'port':"8888", 'type':"http"}, {'ip':"218.241.153.43", 'port':"8080", 'type':"http"}, {'ip':"125.39.93.69", 'port':"8888", 'type':"http"}, {'ip':"211.144.76.7", 'port':"8181", 'type':"http"}, {'ip':"58.53.192.218", 'port':"8123", 'type':"http"}, {'ip':"222.92.141.155", 'port':"8090", 'type':"http"}, {'ip':"59.108.53.1", 'port':"8080", 'type':"http"}, {'ip':"203.93.28.166", 'port':"8080", 'type':"http"}, {'ip':"60.190.189.214", 'port':"8123", 'type':"http"}, {'ip':"59.36.183.178", 'port':"8081", 'type':"http"}, {'ip':"121.11.149.250", 'port':"8081", 'type':"http"}, {'ip':"212.50.244.8", 'port':"8081", 'type':"http"}, {'ip':"216.113.208.185", 'port':"8081", 'type':"http"}, {'ip':"220.181.159.23", 'port':"8080", 'type':"http"}, {'ip':"59.44.204.198", 'port':"8088", 'type':"http"}, {'ip':"221.2.174.164", 'port':"8082", 'type':"http"}, {'ip':"178.135.59.142", 'port':"8090", 'type':"http"}, {'ip':"202.57.4.124", 'port':"8089", 'type':"http"}, {'ip':"211.100.52.196", 'port':"8090", 'type':"http"}, {'ip':"211.144.76.58", 'port':"9000", 'type':"http"} ] def request_domain(domain): have_error = True while have_error: try: url = 'http://pandavip.www.net.cn/check/check_ac1.cgi' user_agent = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)' values = {'domain' : domain,} headers = { 'User-Agent' : user_agent } data = urllib.parse.urlencode(values).encode() req = urllib.request.Request(url, data, headers) index = random.randint(0, len(proxy_list) - 1) proxy = proxy_list[index] if True: proxy_support = urllib.request.ProxyHandler({proxy['type']: proxy['ip'] +':' + proxy['port']}) opener = urllib.request.build_opener(proxy_support) urllib.request.install_opener(opener) response = urllib.request.urlopen(req) the_page = response.read().decode("utf8") except Exception as e: have_error = True proxy_list.pop(index) ## print(">>>>>>>>>>> EXCEPTION: " + proxy['ip']+ " " + str(e)) else: have_error = False else: return the_page def construct_domain(): domainList = [] domainList.append({'pre': "doucube", 'ext': "com"}) domainList.append({'pre': "doucube", 'ext': "net"}) domainList.append({'pre': "doucube", 'ext': "org"}) domainList.append({'pre': "doucube", 'ext': "cn"}) for i in range(97, 123): domain_pre = chr(i) domainList.append({'pre': domain_pre, 'ext': "cn"}) return domainList def main(): domains = construct_domain() for i in range(0, len(domains)): domain_full = domains[i]['pre'] + "." + domains[i]['ext'] result = request_domain(domain_full) cur_time = str(time.strftime("%H:%M:%S", time.localtime())) if result.find("is not available") != -1: print(cur_time + "\t" + domain_full + "\tOccupied!") elif result.find("is available") != -1: print(cur_time + "\t" + domain_full + "\tFREE! ------->$") else: print(cur_time + "\t" + domain_full + "\t" + result) if __name__ == '__main__': main() print(base64.b64decode(b'Q29weXJpZ2h0IChjKSAyMDEyIERvdWN1YmUgSW5jLiBBbGwgcmlnaHRzIHJlc2VydmVkLg==').decode())
运行结果:
*** Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win32. *** >>> *** Remote Interpreter Reinitialized *** >>> 12:21:12 doucube.com Occupied! 12:21:15 doucube.net FREE! ------->$ 12:21:29 doucube.org FREE! ------->$ 12:21:30 doucube.cn FREE! ------->$ 12:21:30 a.cn Occupied! 12:21:33 b.cn Occupied! 12:21:35 c.cn Occupied! 12:21:35 d.cn Occupied! 12:21:37 e.cn Occupied! 12:21:38 f.cn Occupied! 12:21:38 g.cn Occupied! 12:21:42 h.cn Occupied! 12:21:42 i.cn Occupied! 12:21:43 j.cn Occupied! 12:21:45 k.cn Occupied! 12:21:49 l.cn Occupied! 12:21:50 m.cn Occupied! 12:21:50 n.cn Occupied! 12:21:50 o.cn Occupied! 12:21:53 p.cn Occupied! 12:21:53 q.cn Occupied! 12:21:56 r.cn Occupied! 12:21:56 s.cn Occupied! 12:22:06 t.cn Occupied! 12:22:07 u.cn Occupied! 12:22:08 v.cn Occupied! 12:22:08 w.cn Occupied! 12:22:08 x.cn Occupied! 12:22:10 y.cn Occupied! 12:22:11 z.cn Occupied! Copyright (c) 2012 Doucube Inc. All rights reserved. >>>
本文来自博客园,作者:方倍工作室,转载请注明原文链接:https://www.cnblogs.com/txw1958/archive/2012/07/18/check-domains-by-python3.html