zoukankan      html  css  js  c++  java
  • python3 批量处理域名解析

    • 域名批量解析,快速确认域名的存活性及IP地址,脚本中包含了具体的用法和简要说明
    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    # python3.6
    
    from socket import gethostbyname
    import argparse
    
    def domain_ip(openfile,out1,out2,out3):
        with open(openfile, 'r') as f:
            for line in f.readlines():
                try:
                    host = gethostbyname(line.strip('
    '))  # 域名反解析得到的IP
                except Exception as e:
                    with open(out1, 'a+') as ERR:  # A-domain-ERR.txt 解析出错域名统计
                        ERR.write(line.strip() + '
    ')
                else:
                    with open(out2, 'a+') as r:  # A-domain-ip.txt 里面存储的是批量解析后的结果,输出域名
                        r.write(line.strip('
    ') + '  '+ host +"
    ")  # 显示有ip绑定的域名,用空格隔开
                        re = line.strip('
    ')
                        print(re,host)
    					#不包含的解析结果
                        if host.strip() != "127.0.0.0":
                            if host.strip()!= "192.168.1.1":
                                if host.strip() != "192.168.2.1":
                                    if host.strip() != "192.168.3.1":
                                        with open(out3,"a+") as f:
    					f.write(host.strip()+"
    ")
                                            #f.write(line.strip()+"  " + host.strip()+"
    ")
                                    else:
                                        pass
                                else:
                                    pass
                            else:
                                pass
                        else:
                            pass
    
    if __name__== "__main__":
        parser = argparse.ArgumentParser(description="2020.07.28 python 3.6 domain_1.0")
        parser.add_argument('-f'.strip(),'--filename'.strip(), help='eg:-f domains.txt')# 需要解析的域名列表信息
        parser.add_argument('-o'.strip(),'--outfile1'.strip(), default="A-domain-ERR.txt",help='eg:-o A-domain-ERR.txt ')# 输出解析失败的域名信息
        parser.add_argument('-r'.strip(),'--outfile2'.strip(), default="A-domain-ip.txt",help='eg:-r A-domain-ip.txt ')#输出解析成功的域名及ip信息
        parser.add_argument('-a'.strip(), '--outfile3'.strip(), default="A-lists.txt",help='eg:-a A-lists.txt ')#输出A记录列表
        args = parser.parse_args()
        if (args.filename and args.outfile1 and args.outfile2 and args.outfile3):
            domain_ip(args.filename, args.outfile1,args.outfile2,args.outfile3)
        else:
            print(parser.format_help())
    
    
  • 相关阅读:
    第九周个人总结
    用户模板和用户场景
    windows 滚动截图单文件版
    vue一键复制实现 笔记
    django 配置mysql流程以及运行报错的解决
    django urls导入views报错
    python学习2
    python学习1
    spark学习第五天
    spark第四天
  • 原文地址:https://www.cnblogs.com/dddjh/p/13931410.html
Copyright © 2011-2022 走看看