python dig 模拟—— DGA域名判定用
#!/usr/bin/env python import dns.resolver, sys def get_domain_ip(domain):
"""Get the DNS record, if any, for the given domain."""
dns_records = list()
try:
# get the dns resolutions for this domain
dns_results = dns.resolver.query(domain)
dns_records = [ip.address for ip in dns_results]
except dns.resolver.NXDOMAIN as e:
print "the domain does not exist so dns resolutions remain empty. domain:", domain
except dns.resolver.NoAnswer as e:
print "the resolver is not answering so dns resolutions remain empty, domain:", domain
return dns_records hostname = sys.argv[1]
print "Recursive name lookup (simulates dig)..." n=hostname
try:
while True:
for rdata in dns.resolver.query(n, 'CNAME') :
print n, "cname is", rdata
n=rdata.target
except:
print get_domain_ip(n)
例如:
python dig_ip.py 8264.com
Recursive name lookup (simulates dig)...
8264.com cname is qaz2d84guo7uz5q2.gfnormal01at.com.
[u'121.29.18.91'] =>IP地址
python dig_ip.py www.baidu.com
Recursive name lookup (simulates dig)...
www.baidu.com cname is www.a.shifen.com.
www.a.shifen.com. cname is www.wshifen.com.
[u'103.235.46.39', u'103.235.46.40'] =>IP地址
来一个无查询结果的 DGA域名:
python dig_ip.py s09xo3-l5domek9ck5ct3go4m.com
Recursive name lookup (simulates dig)...
the domain does not exist so dns resolutions remain empty. domain: s09xo3-l5domek9ck5ct3go4m.com
[]
其中,dns.resolver.NoAnswer会在查询类别错误时候跑出此异常,例如:
python dig_ip.py www.baidu.com
Recursive name lookup (simulates dig)...
www.baidu.com cname is www.a.shifen.com.
www.a.shifen.com. cname is www.wshifen.com.
The DNS response does not contain an answer to the question: www.wshifen.com. IN CNAME
最后重构下代码:
#!/usr/bin/env python import dns.resolver, sys def get_domain_ip(domain):
"""Get the DNS record, if any, for the given domain."""
dns_records = list()
try:
# get the dns resolutions for this domain
dns_results = dns.resolver.query(domain)
dns_records = [ip.address for ip in dns_results]
except dns.resolver.NXDOMAIN as e:
print "the domain does not exist so dns resolutions remain empty. domain:", domain
except dns.resolver.NoAnswer as e:
print "the resolver is not answering so dns resolutions remain empty, domain:", domain
return dns_records def dig_ip(n):
try:
while True:
for rdata in dns.resolver.query(n, 'CNAME') :
print n, "cname is", rdata
n=rdata.target
except Exception as e:
print e
return get_domain_ip(n) if __name__ == "__main__":
print "Recursive name lookup (simulates dig)..."
print dig_ip(sys.argv[1])
python dig 模拟—— DGA域名判定用的更多相关文章
- 用python实现模拟登录人人网
用python实现模拟登录人人网 字数4068 阅读1762 评论19 喜欢46 我决定从头说起.懂的人可以快速略过前面理论看最后几张图. web基础知识 从OSI参考模型(从低到高:物理层,数据链路 ...
- Python requests模拟登录
Python requests模拟登录 #!/usr/bin/env python # encoding: UTF-8 import json import requests # 跟urllib,ur ...
- python urllib2 模拟网站登陆
python urllib2 模拟网站登陆 1. 可用浏览器先登陆,然后查看网页源码,分析登录表单 2. 使用python urllib2,cookielib 模拟网页登录 import urllib ...
- Python实现模拟登陆
大家经常会用Python进行数据挖掘的说,但是有些网站是需要登陆才能看到内容的,那怎么用Python实现模拟登陆呢?其实网路上关于这方面的描述很多,不过前些日子遇到了一个需要cookie才能登陆的网站 ...
- Python中模拟enum枚举类型的5种方法分享
这篇文章主要介绍了Python中模拟enum枚举类型的5种方法分享,本文直接给出实现代码,需要的朋友可以参考下 以下几种方法来模拟enum:(感觉方法一简单实用) 复制代码代码如下: # way1 ...
- 【小白学爬虫连载(10)】–如何用Python实现模拟登陆网站
Python如何实现模拟登陆爬取Python实现模拟登陆的方式简单来说有三种:一.采用post请求提交表单的方式实现.二.利用浏览器登陆网站记录登陆成功后的cookies,采用get的请求方式,传入c ...
- python 怎么模拟加header(如User-Agent、Content-Type等等)
# -*- coding: cp936 -*- #python 27 #xiaodeng #python 怎么模拟加header(如User-Agent.Content-Type等等) #办法一: i ...
- LSTM网络应用于DGA域名识别--文献翻译--更新中
原文献名称 Predicting Domain Generation Algorithms with Long Short-Term Memory Networks原文作者 Jonathan Wood ...
- python爬虫模拟登陆
python爬虫模拟登陆 学习了:https://www.cnblogs.com/chenxiaohan/p/7654667.html 用的这个 学习了:https://www.cnblogs.co ...
随机推荐
- struts2访问或添加几个属性(request/session/application属性)
https://blog.csdn.net/hebiao100/article/details/7385055 struts2添加request.session.application属性 第一种方法 ...
- iOS第三方地图-百度地图常用功能使用(POI搜索,地理正反编码,定位,添加标注)
百度地图官网: http://developer.baidu.com/map/index.php?title=iossdk 百度地图集成 1.引入相关包
- bzoj 1500 [NOI 2005] 维修数列
题目大意不多说了 貌似每个苦逼的acmer都要做一下这个splay树的模版题目吧 还是有很多操作的,估计够以后当模版了.... #include <cstdio> #include < ...
- SGU 106 The equation【扩展欧几里得】
先放一张搞笑图.. 我一直wa2,这位不认识的大神一直wa9...这样搞笑的局面持续了一个晚上...最后各wa了10发才A... 题目链接: http://acm.hust.edu.cn/vjudge ...
- 洛谷——P1547 Out of Hay
P1547 Out of Hay 题目背景 奶牛爱干草 题目描述 Bessie 计划调查N (2 <= N <= 2,000)个农场的干草情况,它从1号农场出发.农场之间总共有M (1 & ...
- MongoDB学习day09--Mongoose数据校验
一.Mongoose检验参数 required : 表示这个数据必须传入max: 用于 Number 类型数据, 最大值 min: 用于 Number 类型数据, 最小值 enum:枚举类型, 要求数 ...
- HDU 4786 Fibonacci Tree(生成树,YY乱搞)
http://acm.hdu.edu.cn/showproblem.php? pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others ...
- Ubuntu更换主板之后 网络重新配置
Ubuntu更换主板之后,网络不能用,需要重新配置 1. 首要要查看新主板的mac地址, dmesg | grep eth 2. 修改网络信息,该配置文件是/etc/udev/rules.d, 文 ...
- 改动Android启动画面
一.Android的启动步骤 1.启动Linux 2.载入Android 3.显示Android桌面 二.分析 Android载入开机动画的源代码文件是: /opt/android4.3/framew ...
- 架构设计经典案例:X窗体系统
X Window在1984年由MIT研发.它的设计哲学之中的一个是:提供机制.而非策略(类似面向对象思想中的"针对接口编程,而不是针对实现编程").机制(mechanism)是指须 ...