• 域名批量解析,快速确认域名的存活性及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('\n')) # 域名反解析得到的IP
except Exception as e:
with open(out1, 'a+') as ERR: # A-domain-ERR.txt 解析出错域名统计
ERR.write(line.strip() + '\n')
else:
with open(out2, 'a+') as r: # A-domain-ip.txt 里面存储的是批量解析后的结果,输出域名
r.write(line.strip('\n') + ' '+ host +"\n") # 显示有ip绑定的域名,用空格隔开
re = line.strip('\n')
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()+"\n")
#f.write(line.strip()+" " + host.strip()+"\n")
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())

最新文章

  1. python操作Excel读写--使用xlrd和xlwt
  2. 038. asp.netWeb用户控件之六实现日期选择的用户控件
  3. uva 11728 Alternate Task
  4. VxWorks 6.9 内核编程指导之读书笔记 -- 多任务
  5. storm sum aggregate 原语 聚合 本地测试
  6. Altium自定义的快捷键设置
  7. php xcache 配置 使用 (转载)
  8. Mono for Android 显示远程图片
  9. java 子类与父类继承关系
  10. Java中常见的数据结构的区别
  11. 【一天一道LeetCode】#17. Letter Combinations of a Phone Number
  12. Nginx隐藏index.php和配置vhost
  13. C# groupby 应用小技巧
  14. 第60节:Java中的JavaScript技术
  15. Confluence 6 自定义管理员联系信息
  16. MySQL性能调优的10个方法 - mysql数据库栏目
  17. topcoder srm 694 div1 -3
  18. get android or ios appname
  19. MySQL程序之mysqlshow详解
  20. vs2017调试浏览器闪退

热门文章

  1. Codeforces Round #653 (Div. 3) C. Move Brackets
  2. 使用开源量子编程框架ProjectQ打印编译后的量子线路与绘制线路图
  3. Python——控制鼠标键盘
  4. kubernetes实战-交付dubbo服务到k8s集群(一)准备工作
  5. Linux添加系统调用
  6. Shell 编程快速上手
  7. Protocol Buffers All In One
  8. VSCode 开放式架构的产品实现思路
  9. Markdown & Static Site Generator
  10. Teadocs & markdown website