parent
03c88ce5da
commit
873dadc628
@ -1,25 +1,149 @@ |
|||||||
#域名注册检测 |
import os |
||||||
import jsons as jsons |
import string |
||||||
|
import time |
||||||
|
|
||||||
import requests |
import requests |
||||||
|
import json |
||||||
|
from openpyxl import Workbook, load_workbook |
||||||
|
from config.log import writeInfo |
||||||
|
from requests_toolbelt.multipart.encoder import MultipartEncoder |
||||||
|
|
||||||
|
|
||||||
|
def colname_to_num(colname): |
||||||
|
if type(colname) is not str: |
||||||
|
return colname |
||||||
|
|
||||||
|
col = 0 |
||||||
|
power = 1 |
||||||
|
|
||||||
|
for i in range(len(colname) - 1, -1, -1): |
||||||
|
ch = colname[i] |
||||||
|
|
||||||
|
col += (ord(ch) - ord('a') + 1) * power |
||||||
|
|
||||||
|
power *= len(string.ascii_lowercase) |
||||||
|
|
||||||
|
return col |
||||||
|
|
||||||
headers = { |
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36', |
def column_to_name(colnum): |
||||||
'Referer': 'https://domain.oray.com/suffix/xyz.html' |
if type(colnum) is not int: |
||||||
} |
return colnum |
||||||
|
|
||||||
if __name__ == '__main__': |
str = '' |
||||||
i = 1 |
|
||||||
while True: |
str_l = len(string.ascii_lowercase) |
||||||
domain='%d.xyz' % i |
while (not (colnum // str_l == 0 and colnum % str_l == 0)): |
||||||
response = requests.get('https://mcheck.oray.com/domain/check?domain[]=%s&record=1' % domain, headers=headers) |
|
||||||
if response.status_code == 200: |
temp = str_l - 1 |
||||||
content = response.content.decode(response.apparent_encoding) |
|
||||||
if content.startswith('{') and content.endswith('}'): |
if (colnum % str_l == 0): |
||||||
content = jsons.loads(content) |
str += chr(temp + ord('a')) |
||||||
if domain in content and 'avail' in content[domain] and content[domain]['avail']==1: |
|
||||||
print('域名:%s未注册' % domain) |
|
||||||
else: |
|
||||||
print('域名:%s已注册' % domain) |
|
||||||
else: |
else: |
||||||
print('error') |
str += chr(colnum % str_l - 1 + ord('a')) |
||||||
i = i + 1 |
|
||||||
|
colnum //= str_l |
||||||
|
# 倒序输出拼写的字符串 |
||||||
|
return str[::-1] |
||||||
|
|
||||||
|
|
||||||
|
def aliyun(domain: str, error_file: str, datas: list): |
||||||
|
url = f'https://checkapi.aliyun.com/check/checkdomain?domain={domain}&command=&token=Ybd4a4cee48911b5a42fb04958c7fd25f' |
||||||
|
writeInfo(f'url={url}') |
||||||
|
res = requests.get(url) |
||||||
|
|
||||||
|
if res.status_code == 200: |
||||||
|
res_json = json.loads(res.content) |
||||||
|
try: |
||||||
|
if res_json['module'][0]['avail'] == 1: |
||||||
|
price = res_json['module'][0]['price'] |
||||||
|
writeInfo(f'{domain}可注册,价格{price}') |
||||||
|
time.sleep(0.5) |
||||||
|
datas.append((domain, f'{price}¥')) |
||||||
|
else: |
||||||
|
writeInfo(f'{domain}已注册') |
||||||
|
except: |
||||||
|
with open(error_file, 'a', encoding='utf-8') as f: |
||||||
|
f.write(f'{domain}\n') |
||||||
|
else: |
||||||
|
raise Exception('请求异常') |
||||||
|
|
||||||
|
|
||||||
|
def check(top_domain: list, start: str, end: str, supportMany: bool, todo): |
||||||
|
if not isinstance(top_domain, list) or len(top_domain) == 0: |
||||||
|
raise Exception('top_domain不合法') |
||||||
|
|
||||||
|
if not str.isalpha(start): |
||||||
|
raise Exception('start不合法') |
||||||
|
if not str.isalpha(end) or colname_to_num(end) <= colname_to_num(start): |
||||||
|
raise Exception('end不合法') |
||||||
|
if not isinstance(supportMany, bool): |
||||||
|
raise Exception('isExec不合法') |
||||||
|
|
||||||
|
domain_file = 'domain.xlsx' |
||||||
|
error_file = 'error.txt' |
||||||
|
|
||||||
|
if os.path.exists(domain_file): |
||||||
|
wb = load_workbook(domain_file) |
||||||
|
else: |
||||||
|
wb = Workbook() |
||||||
|
ws = wb.active |
||||||
|
if ws.max_row == 1: |
||||||
|
ws.cell(1, 1, '域名') |
||||||
|
ws.cell(1, 2, '价格') |
||||||
|
if os.path.exists(error_file): |
||||||
|
os.remove(error_file) |
||||||
|
for i in range(colname_to_num(start), colname_to_num(end)+1): |
||||||
|
datas = list() |
||||||
|
if supportMany: |
||||||
|
todo([f'{column_to_name(i)}.{x}' for x in top_domain], error_file, datas) |
||||||
|
else: |
||||||
|
for j in top_domain: |
||||||
|
domain = f'{column_to_name(i)}.{j}' |
||||||
|
todo(domain, error_file, datas) |
||||||
|
|
||||||
|
for index, data in enumerate(datas): |
||||||
|
domain, price = data |
||||||
|
row = ws.max_row + 1 |
||||||
|
ws.cell(row, 1, domain) |
||||||
|
ws.cell(row, 2, price) |
||||||
|
wb.save(domain_file) |
||||||
|
|
||||||
|
|
||||||
|
def namesilo(domains: list, error_file: str, datas: list): |
||||||
|
data = tuple([('tlds[]', x.split('.')[1]) for x in domains] + [('domains[]', x) for x in domains]) |
||||||
|
m = MultipartEncoder( |
||||||
|
fields=data) |
||||||
|
res = requests.post('https://www.namesilo.com/public/api/domains/bulk-check', data=m, |
||||||
|
headers={'Content-Type': m.content_type}) |
||||||
|
if res.status_code == 200: |
||||||
|
json_res = json.loads(res.content) |
||||||
|
if 'result' in json_res and json_res['result'] == 'success' and 'data' in json_res and 'checkId' in json_res[ |
||||||
|
'data']: |
||||||
|
checkId = json_res['data']['checkId'] |
||||||
|
url = f'https://www.namesilo.com/public/api/domains/results/{checkId}' |
||||||
|
res = requests.get(url) |
||||||
|
if res.status_code == 200: |
||||||
|
json_res = json.loads(res.content) |
||||||
|
for domain in json_res['data']['domains']: |
||||||
|
d = domain['domain'] |
||||||
|
if domain['available']: |
||||||
|
price = domain['currentPrice'] |
||||||
|
writeInfo(f'{d}可注册,价格{price}') |
||||||
|
datas.append((d, f'{round(price, 2)}$')) |
||||||
|
else: |
||||||
|
writeInfo(f'{d}已注册') |
||||||
|
|
||||||
|
else: |
||||||
|
raise Exception('请求异常') |
||||||
|
else: |
||||||
|
writeInfo(json_res) |
||||||
|
else: |
||||||
|
with open(error_file, 'a', encoding='utf-8') as f: |
||||||
|
for domain in domains: |
||||||
|
f.write(f'{domain}\n') |
||||||
|
raise Exception('请求异常') |
||||||
|
|
||||||
|
|
||||||
|
# check(['top', 'fun', 'online', 'ink', 'ren', 'site', 'asia'], 'aaa', 'aag', False, aliyun) |
||||||
|
|
||||||
|
@ -0,0 +1,3 @@ |
|||||||
|
home = E:\Python\Python37 |
||||||
|
include-system-site-packages = false |
||||||
|
version = 3.7.8 |
Loading…
Reference in new issue