当前位置:网站首页>批量检测url是否存在cdn—高准确率
批量检测url是否存在cdn—高准确率
2022-07-02 02:28:00 【山山而川'】
看了网上对url批量检测cdn的脚本没有多少也不准确,这里写一下
一般判断cdn的方法如下
全球ping
显示的ip地址超过一个则使用了cdn,这是最靠谱的方法
nslookup
1. nslookup默认解析
使用 "nslookup 域名",如果目标有CDN服务的话,那么“非权威应答”中的“addresses”中的IP数 >=2个,但是也会有误报

2. 不同DNS域名解析
不同DNS域名解析情况对比,判断其是否使用了CDN。不同DNS解析结果若不一样,很有可能存在CDN服务
所以我们可以根据这两点来判断是否使用了cdn
批量检测脚本
如果引用全球ping的api接口进行检测,那检测效率会受限于服务器网速以及可能遇到被封ip的风险。这里使用nslookup进行多次检测,以确认是否使用cdn,准确率99%

cdn.py
from subprocess import PIPE, Popen
import re
import os
from colorama import init,Fore
init(autoreset=True)
import argparse
def args():
parser = argparse.ArgumentParser(description='cdn批量检测脚本')
parser.add_argument('-f',type=str,help='批量检测,请将url放在txt文档中,一个一行')
args = parser.parse_args()
ssrc = """
______ _____________ ____
/ ___/ / ___/\_ __ \_/ ___\
\___ \ \___ \ | | \/\ \___
/____ >/____ > |__| \___ >
\/ \/ \/
Author: 山山而川
"""
print(ssrc)
if args.f:
filename = args.f
if os.path.exists(filename):
check_cdn(filename)
else:
print("输入的文件名不存在!")
def check_cdn(filename):
result_list = []
for url in open(filename,'r'):
url = url.replace("\n","")
ip = url.replace("http://","").replace("https://","").replace("/","").replace("\n","")
proc = Popen('nslookup %s' %(ip),stdin=None,stdout=PIPE,stderr=PIPE,shell=True)
outinfo, errinfo = proc.communicate()
info = outinfo.decode('gbk')
ip_list = re.findall(r"\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}",info,re.S)
if len(ip_list) >= 3:
print(Fore.RED+"[-]",url," 存在cdn")
continue
if len(ip_list) == 1:
print(Fore.BLUE+"[-]",url," 请求超时")
continue
if len(ip_list) == 2:
#二次判断,提高准确率
proc = Popen('nslookup %s 223.5.5.5' %(ip),stdin=None,stdout=PIPE,stderr=PIPE,shell=True)
outinfo, errinfo = proc.communicate()
info1 = outinfo.decode('gbk')
ip_list1 = re.findall(r"\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}",info1,re.S)
if len(ip_list1) >= 3:
print(Fore.RED+"[-]",url," 存在cdn")
continue
if len(ip_list1) ==2:
name1 = re.findall(r'名称:.*Address:.*?(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})',info,re.S)[0]
name2 = re.findall(r'名称:.*Address:.*?(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})',info1,re.S)[0]
if name1 != name2:
print(Fore.RED+"[-]",url," 存在cdn")
continue
if name1 == name2:
print(Fore.GREEN+"[+] %s 不存在cdn \t真实ip: %s" %(url,name2))
result_list.append(name2)
lis = list(set(result_list))
if len(lis):
for r in lis:
with open("result.txt",'a') as f:
f.write(r+"\n")
print("检测完毕,不存在cdn的url ip保存在当前路径'result.txt'")
if not len(lis):
print("检测完毕!")
if __name__ == '__main__':
args()边栏推荐
- Infix expression to suffix expression (computer) code
- leetcode2309. 兼具大小写的最好英文字母(简单,周赛)
- Divorce for 3 years to discover the undivided joint property, or
- MySQL operates the database through the CMD command line, and the image cannot be found during the real machine debugging of fluent
- how to add one row in the dataframe?
- 花一个星期时间呕心沥血整理出高频软件测试/自动化测试面试题和答案
- leetcode373. Find and minimum k-pair numbers (medium)
- Additional: information desensitization;
- Is bone conduction earphone better than traditional earphones? The sound production principle of bone conduction earphones is popular science
- 【OpenCV】-5种图像滤波的综合示例
猜你喜欢

MySQL中一条SQL是怎么执行的

If you want to rewind the video picture, what simple methods can you use?

附加:信息脱敏;

【liuyubobobo-玩转Leetcode算法面试】【00】课程概述

【带你学c带你飞】1day 第2章 (练习2.2 求华氏温度 100°F 对应的摄氏温度
![[question 008: what is UV in unity?]](/img/f7/5ee0b18d1fe21ff3b98518c46d9520.jpg)
[question 008: what is UV in unity?]

Types of exhibition items available in the multimedia interactive exhibition hall

Architecture evolution from MVC to DDD

The wave of layoffs in big factories continues, but I, who was born in both non undergraduate schools, turned against the wind and entered Alibaba

Which brand of running headphones is good? How many professional running headphones are recommended
随机推荐
leetcode2312. Selling wood blocks (difficult, weekly race)
JVM interview
剑指 Offer 47. 礼物的最大价值
es面试题
研发中台拆分过程的一些心得总结
【带你学c带你飞】3day第2章 用C语言编写程序(练习 2.3 计算分段函数)
Is bone conduction earphone better than traditional earphones? The sound production principle of bone conduction earphones is popular science
CVPR 2022 | Dalian Institute of technology proposes a self calibration lighting framework for low light level image enhancement of real scenes
* and & symbols in C language
leetcode2309. 兼具大小写的最好英文字母(简单,周赛)
Summary of some experiences in the process of R & D platform splitting
query词权重, 搜索词权重计算
Realize the code scanning function of a custom layout
Kibana controls es
Software development life cycle -- waterfall model
Which is a good Bluetooth headset of about 300? 2022 high cost performance Bluetooth headset inventory
2022安全员-C证考试题及模拟考试
Post infiltration flow encryption
MySQL主从延迟问题怎么解决
超图iServer rest服务之feature查询