python3 批量处理域名解析
2024-10-10 10:11:02
- 域名批量解析,快速确认域名的存活性及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())
最新文章
- python操作Excel读写--使用xlrd和xlwt
- 038. asp.netWeb用户控件之六实现日期选择的用户控件
- uva 11728 Alternate Task
- VxWorks 6.9 内核编程指导之读书笔记 -- 多任务
- storm sum aggregate 原语 聚合 本地测试
- Altium自定义的快捷键设置
- php xcache 配置 使用 (转载)
- Mono for Android 显示远程图片
- java 子类与父类继承关系
- Java中常见的数据结构的区别
- 【一天一道LeetCode】#17. Letter Combinations of a Phone Number
- Nginx隐藏index.php和配置vhost
- C# groupby 应用小技巧
- 第60节:Java中的JavaScript技术
- Confluence 6 自定义管理员联系信息
- MySQL性能调优的10个方法 - mysql数据库栏目
- topcoder srm 694 div1 -3
- get android or ios appname
- MySQL程序之mysqlshow详解
- vs2017调试浏览器闪退
热门文章
- Codeforces Round #653 (Div. 3) C. Move Brackets
- 使用开源量子编程框架ProjectQ打印编译后的量子线路与绘制线路图
- Python——控制鼠标键盘
- kubernetes实战-交付dubbo服务到k8s集群(一)准备工作
- Linux添加系统调用
- Shell 编程快速上手
- Protocol Buffers All In One
- VSCode 开放式架构的产品实现思路
- Markdown &; Static Site Generator
- Teadocs &; markdown website