Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mouday committed Apr 16, 2023
1 parent 7dafb58 commit f6b30c0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
12 changes: 9 additions & 3 deletions domain_admin/utils/whois_util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

# 默认的配置,适用于大部分域名查询
DEFAULT_WHOIS_CONFIG = {
'whois_server': '', # whois查询服务器
'whois_server': '', # whois查询服务器
# 'error': 'No match', # 错误信息
'registry_time': 'Creation Date', # 注册时间
'registry_time': 'Creation Date', # 注册时间
'expire_time': 'Registry Expiry Date' # 过期时间
}

Expand All @@ -22,8 +22,14 @@
CUSTOM_WHOIS_CONFIGS = {
'cn': {
'whois_server': 'whois.cnnic.cn',
# 'error': 'Invalid parameter',
'registry_time': 'Registration Time',
'expire_time': 'Expiration Time',
},
'hk': {
'whois_server': 'whois.hkirc.hk',
'registry_time': 'Domain Name Commencement Date',
"registry_time_format": '%d-%m-%Y',
'expire_time': 'Expiry Date',
"expire_time_format": '%d-%m-%Y',
}
}
2 changes: 1 addition & 1 deletion domain_admin/utils/whois_util/whois-servers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ tel whois.nic.tel
tf whois.nic.tf
th whois.thnic.net
tj whois.nic.tj
tk whois.nic.tk
tk whois.dot.tk
tl whois.domains.tl
tm whois.nic.tm
tn whois.ati.tn
Expand Down
23 changes: 21 additions & 2 deletions domain_admin/utils/whois_util/whois_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
import json
from copy import deepcopy
from datetime import datetime

from dateutil import parser

Expand All @@ -16,6 +17,21 @@
WHOIS_CONFIGS = None


def parse_time(time_str, time_format=None):
"""
解析时间字符串为时间对象
:param time_str:
:param time_format:
:return:
"""
if time_format:
time_parsed = datetime.strptime(time_str, time_format)
else:
time_parsed = parser.parse(time_str).replace(tzinfo=None)

return time_parsed


def load_whois_servers_config():
"""
加载whois_servers配置
Expand Down Expand Up @@ -69,6 +85,8 @@ def get_domain_whois(domain):
# error = whois_config['error']
registry_time = whois_config['registry_time']
expire_time = whois_config['expire_time']
registry_time_format = whois_config.get('registry_time_format')
expire_time_format = whois_config.get('expire_time_format')

raw_data = get_whois_raw(domain, whois_server, timeout=10)
logger.debug(raw_data)
Expand All @@ -83,9 +101,10 @@ def get_domain_whois(domain):
expire_time = data.get(expire_time)

if start_time:
start_time = parser.parse(start_time).replace(tzinfo=None)
start_time = parse_time(start_time, registry_time_format)

if expire_time:
expire_time = parser.parse(expire_time).replace(tzinfo=None)
expire_time = parse_time(expire_time, expire_time_format)

if start_time and expire_time:
return {
Expand Down
5 changes: 4 additions & 1 deletion tests/utils/test_whois_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ def test_get_domain_info():
# '126.net'

# biz
'all.biz'
# 'all.biz'

'dot.tk'
]


for domain in domain_list:
# print(parse_whois_raw(get_whois_raw(domain, ROOT_SERVER)))
print(whois_util.get_domain_info(domain))

0 comments on commit f6b30c0

Please sign in to comment.