Skip to content

Commit

Permalink
优化 接入新icp接口
Browse files Browse the repository at this point in the history
  • Loading branch information
mouday committed Jul 22, 2023
1 parent 9f791fc commit 168b4b4
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 3 deletions.
4 changes: 4 additions & 0 deletions domain_admin/service/domain_info_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import time
import traceback
from datetime import datetime, timedelta
import random

from peewee import chunked

Expand Down Expand Up @@ -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):
"""
Expand Down
89 changes: 86 additions & 3 deletions domain_admin/utils/icp_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<data>.*)\)", 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
Expand Down Expand Up @@ -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))

0 comments on commit 168b4b4

Please sign in to comment.