diff --git a/domain_admin/service/domain_info_service.py b/domain_admin/service/domain_info_service.py index b26045af84..b3113f45a7 100644 --- a/domain_admin/service/domain_info_service.py +++ b/domain_admin/service/domain_info_service.py @@ -8,6 +8,7 @@ import time import traceback from datetime import datetime, timedelta +import random from peewee import chunked @@ -167,6 +168,9 @@ def update_all_domain_icp_of_user(user_id): for row in rows: update_domain_row_icp(row) + # 防止过于频繁 + time.sleep(random.randint(3, 10)) + def update_domain_row_icp(row): """ diff --git a/domain_admin/utils/icp_util.py b/domain_admin/utils/icp_util.py index 54c2c1b412..75a65f9248 100644 --- a/domain_admin/utils/icp_util.py +++ b/domain_admin/utils/icp_util.py @@ -4,12 +4,81 @@ @Date : 2023-06-30 """ from __future__ import print_function, unicode_literals, absolute_import, division + +import json +import re + import requests +from domain_admin.log import logger from domain_admin.utils import json_util -def get_icp(domain): +class ICPItem(object): + name = '' + icp = '' + + def to_dict(self): + return { + 'name': self.name, + 'icp': self.icp, + } + + +def get_icp_from_qq(domain): + """ + 接口由网友提供 + :param domain: + :return: + + ({ + "data": { + "retcode": 0, + "results": { + "url": "baidu.com", + "whitetype": 3, + "WordingTitle": "", + "Wording": "", + "detect_time": "1657588645", + "eviltype": "0", + "certify": 0, + "isDomainICPOk": 1, + "Orgnization": "北京百度网讯科技有限公司", + "ICPSerial": "京ICP证030173号-1" + } + }, + "reCode": 0 + }) + """ + url = 'https://cgi.urlsec.qq.com/index.php' + + params = { + 'm': 'check', + 'a': 'check', + 'url': domain + } + + headers = { + 'Referer': 'https://guanjia.qq.com' + } + + res = requests.get(url, params, headers=headers) + + logger.debug(res.text) + + ret = re.match("\((?P.*)\)", res.text) + + if ret: + data = ret.groupdict().get('data') + results = json.loads(data).get('data').get('results') + + item = ICPItem() + item.name = results.get('Orgnization', '') + item.icp = results.get('ICPSerial', '') + return item + + +def get_icp_from_vvhan(domain): """ 查询域名备案信息 doc: https://api.vvhan.com/beian.html @@ -37,8 +106,22 @@ def get_icp(domain): 'url': domain } res = requests.get(url, params) - return res.json().get('info') + + logger.debug(res.text) + + info = res.json().get('info') + + item = ICPItem() + item.name = info.get('name', '') + item.icp = info.get('icp', '') + + return item + + +def get_icp(domain): + return get_icp_from_qq(domain).to_dict() if __name__ == '__main__': - print(json_util.json_encode(get_icp('baidu.com'), indent=2, ensure_ascii=False)) + # print(json_util.json_encode(get_icp('baidu.com'), indent=2, ensure_ascii=False)) + print(json_util.json_encode(get_icp_from_qq('baidu.com').to_dict(), indent=2, ensure_ascii=False))