python- 云防护接入判断
- 原理:云防护的判断主要通过判断cname特征名,如接入创宇盾,cname中会有365cyd这串字符,如接入玄武盾,cname中则会有dbapp;cname和ip的获取主要通过解析模块。
- 代码
- 输入
- 输出
代码
import socket
import dns.resolver
def url2domain(url):
if("http" in url):
url = url[7:]
elif("https" in url):
url = url[8:]
if("/" in url):
url = url.split("/")[0]
return url
def domain2ip(domain):
try:
ip = socket.gethostbyname(domain)
except:
ip = "解析错误"
return ip
def domain2cname(domain):
try:
CNAME = dns.resolver.query(domain,'CNAME')
for i in CNAME.response.answer:
for j in i.items:
cname = j.to_text()
except:
cname = "未解析"
return cname
def wafjudge(cname):
if("365cyd" in cname):
waf = "创宇盾"
elif("ali" in cname):
waf = "阿里云防护"
elif("dbapp" in cname):
waf = "安恒玄武盾"
elif("未解析" in cname):
waf = "未接入云防护"
else:
waf = "其他云防护"
return waf
urllist=open("url.txt","r")
waflist=open("waf.txt","w")
iplist =open("ip.txt","w")
cnamelist = open("cname.txt","w")
domainlist = open("domain.txt","w")
for oneurl in urllist.readlines():
oneurl = oneurl.replace("\n","")
oneurl = oneurl.replace(" ","")
domain = url2domain(oneurl)
ip = domain2ip(domain)
cname = domain2cname(domain)
waf = wafjudge(cname)
waflist.write(waf+"\n")
iplist.write(ip+"\n")
cnamelist.write(cname+"\n")
domainlist.write(domain+"\n")
urllist.close()
waflist.close()
iplist.close()
cnamelist.close()
domainlist.close()
输入
- 输入是一行一个url 的txt文件,以下是文件内容例子
http://www.kq.gov.cn/
rsj.kq.gov.cn
http://www.shaoxingsx.jcy.gov.cn/
http://www.sxxjsj.gov.cn/
http://www.kqqcjda.cn/
输出
- ip.txt
220.191.226.18
220.191.226.18
223.202.67.54
60.190.216.117
183.61.0.169
- domain.txt
www.kq.gov.cn
rsj.kq.gov.cn
www.shaoxingsx.jcy.gov.cn
www.sxxjsj.gov.cn
www.kqqcjda.cn
- cname.txt
未解析
未解析
未解析
未解析
未解析
- waf.txt
未接入云防护
未接入云防护
未接入云防护
未接入云防护
未接入云防护