python3批量查询域名是否注册

本文介绍了一个使用Python编写的简单工具,该工具可以检查多个域名的注册状态。通过调用外部API并利用代理服务器列表来避免IP被封禁的风险,此脚本能够有效地批量查询域名是否已被占用。
#!/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.

>>> 

 

本软件能快速扫描域名注册情况,批量导出导入,速度快,站长朋友不可多得的好工具,如今查找已备案域名比较困难,此工具配合已备案域名查询网】效果极佳。 版本介绍: ======================================================== 2008-7-23 版本 1.2.0 增加最小化到托盘图标的功能,可即时了解查找情况 增加导出格式选择,详细列表和域名字典库2种 修正部分小错误 2008-3-18 版本 1.0.7 由于CN类的whois服务器长期不稳定,在新版本中取消该类域名查询, 直到服务稳定为止! 望各位用户谅解。 2007-11-20 版本 1.0.6 限制线程总数,最高只能为10线程(因为对于某些服务器造成了负荷) 关闭了搜索情况的提醒 增加了搜索过程的详细信息 更换了部分注册查询服务器 修正.COM等顶级国际域名的搜索 2007-11-12 版本 1.0.3 增加单域名搜索方式 详细各输入栏目的描述 2007-11-8 版本 1.0.1 增强域名选择的弹出窗口 增加代理设置管理界面 修正部分后缀的校验代码 2007-10-11 版本 1.0.0 增加检测搜索状态,如果在开始的1分钟内,搜索量低于10个,将停止并给予解决意见 修正部分界面操作故障 修改域名的检查时间改为无限时,直到1个域名检查到确实的注册情况 增加一个显示域名的详细注册情况的网站,在程序中可以引导过去 2007-9-11 版本 0.9.5.0 修复部分失效的域名注册查询网站(解决最近出现的检测时丢失域名的问题) 2007-8-6 版本 0.9.3.0 增加支持HTTP代理服务器模式 增加支持线程数的设置 增加自动检查新版本,并在线升级功能 增加中文字词转换到拼音的功能,由于多音字的问题,建议只作为参考使用 单域名查询通过输入前缀名称并将随机位数设置为零来实现查询 2007-7-31 版本 0.9.0.0 增加词库模式搜索 增加多后缀搜索,允许对同一个域名进行多个后缀的搜索 2007-7-18 版本 0.8.0.0 修正顺序搜索时的前后缀丢失问题 修正搜索时有重复域名的错误 增加域名列表时的右键快捷功能菜单 缩短停止搜索时的等待时间 增加顺序域名搜索功能 增强搜索过程中的细节显示 2007-7-3 版本 0.7.5.0 优化界面 增加注册向导 增加.cn域名的最新到期名单功能,并能够自动更新 增加相关资讯及网站 增加支持cc,cn,com.cn,net.cn,org.cn,gov.cn,tv这些域名 2007-6-13 版本 0.5.1.3 优化搜索模块,提高搜索速度 2006-09-13 12:00 版本 测试版 0.2.5.0 第一版发布 1.支持英文、数字、英文数字混合域名,随机组合进行检查。 2.支持多种国际顶级域名 3.如果域名已经注册,记录域名的失效日期。 4.提高检查速度。 5.单域名查询
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值