域名报红检测小工具-python – 记忆角落

域名报红检测小工具-python

/ 2评 / 0

域名爆红检测小工具,方便做识别批量检查,作为另一种思路

#!/usr/bin/env python3
# _*_ coding:utf-8 _*_

import json
import time
import requests


def check_file(file):
    str_dump = []
    line_len = 100
    with open(file, 'r') as f1:
        for line in f1:
            line = line.replace('\n', '')
            print(line)
            # link = 'https://cgi.urlsec.qq.com/index.php?m=check&a=check&url=http://{}'.format(line)
            t = int(round(time.time()*1000))
            link = 'https://cgi.urlsec.qq.com/index.php?m=check&a=check&callback=jQuery1113049533065324068226_1585819829729&url={0}&_={1}'.format(line, t)
            try:
                # 接口header
                headers = {
                    "Content-Type": "application/json;charset=utf-8",
                    "Accept": "*/*",
                    "Connection": "keep-alive",
                    "Host": "cgi.urlsec.qq.com",
                    # "Referer": "https://guanjia.qq.com",
                    "Referer": "https://urlsec.qq.com/check.html?url={}".format(line),
                    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36 Edg/88.0.705.74",
                }

                req = requests.get(link, headers=headers, timeout=100)
                # print(req)
                response = req.text
                # print(response[len('jQuery1113049533065324068226_1585819829729('):len(response)-1])
                data = json.loads(response[len('jQuery1113049533065324068226_1585819829729('):len(response)-1])

                # whitetype: 1:安全性未知 2:危险网站 3:安全网站
                white_type = data['data']['results']['whitetype']
                # python 没switch 语法 害
                if white_type == 1:
                    type_str = 'unknown'
                elif white_type == 2:
                    type_str = 'danger'
                elif white_type == 3:
                    type_str = 'safe'
                else:
                    type_str = 'null'

                str_data = line + ',' + type_str + ',' + str(white_type) + '\n'
                str_dump.append(str_data)
                req.close()

            except Exception as e:
                print(e)

            if len(str_dump) > 0:
                if (len(str_dump) % line_len) == 0:
                    # print('够{}条啦...'.format(len(str_dump)))
                    with open('target_qq.txt', 'a+') as f3:
                        f3.write(''.join(str_dump))
                        str_dump = []

            time.sleep(0.1)

    if len(str_dump) > 0:
        with open('target_qq.txt', 'a+') as f3:
            f3.write(''.join(str_dump))
            str_dump = []


if __name__ == '__main__':
    check_file('url.txt')

 

《“域名报红检测小工具-python”》 有 2 条评论

  1. 百度飘红能检测不

发表评论

您的电子邮箱地址不会被公开。