UI设计 薇晓朵数字商城

 找回密碼
 加入我們

小腳本分享:批量檢查域名是否可以註冊

[複製鏈接]
小猪哼囔 發表於 2023-12-1 22:18:41 | 顯示全部樓層 |閱讀模式
源代碼直鏈 https://pastebin.com/raw/LjsnW5Jv,直接curl下來即可,用python寫的,依賴外部命令whois,linux系統用apt之類的裝就行

可以自己修改配置任意後綴,長度,字符表,具體用法已經寫代碼註釋裡了

  1. #!/usr/bin/env python3
  2. # VERSION: 23.11.23
  3. # LICENSE: CC0
  4. # AUTHOR: Cagamine Lin
  5. #
  6. # Usage:
  7. # 脚本依赖于系统的whois命令,跑之前请确保已安装
  8. # 然后自己查询一次对应后缀未注册和已注册域名的输出
  9. # 找到关键词填入sample和sample_fail参数
  10. # sample 通常是类似'not found','not match'的文本
  11. # sample_fail,通常是类似'create time','expiry time'的文本
  12. #   - 可以留空,这样会在没搜索到sample时当已注册处理,
  13. #   - 不留空,则会既没搜索到sample,又没sample_fail时标记为 [?] , 以便您另外查
  14. # 关键词不要写太短,防止匹配的后面的注释导致误差, 有标点最好也带上
  15. # 最后把后缀,长度,字符表分别填入参数suffix, length, chars

  16. WORD = 'abcdefghijklmnopqrstuvwxyz'
  17. DIG = '0123456789'

  18. # Begin of params
  19. sample = 'was not found.'
  20. sample_fail = ''
  21. suffix = 'im'
  22. length = 3

  23. # chars = DIG+WORD
  24. # chars = DIG
  25. chars = WORD
  26. # End of params

  27. import subprocess
  28. from time import sleep
  29. from datetime import datetime
  30. from itertools import product


  31. def check(target, sample, sample_fail='', retry_rule=[5, 5, 20]):
  32.     retry = 0
  33.     while True:
  34.         try:
  35.             output = subprocess.check_output(
  36.                 ['whois', target], shell=False, text=True)
  37.             if sample in output:
  38.                 return 'ok'
  39.             if sample_fail in output:
  40.                 return 'fail'

  41.             raise Exception('unknown ')

  42.         except Exception as e:
  43.             print(e)
  44.             retry += 1
  45.             sleep(retry_rule[retry])

  46.         if retry > len(retry_rule):
  47.             return 'unknown'


  48. def run(chars, length, suffix, sample, sample_fail='', retry_rule=[5, 5, 20], save=True):
  49.     filename = save == True and datetime.now().strftime(
  50.         f"{suffix}-{length}_%y-%m-%d_%H%M%S.txt")
  51.     file = save and open(filename, "w")
  52.     log = save and (lambda s: (file.write(s+'\n'),
  53.                     file.flush())) or (lambda s: s)

  54.     print('# Targets:')
  55.     print('[%s]{%d}.%s\n' % (chars, length, suffix))
  56.     print('# Report:', save and f'(save to {filename})' or '')

  57.     it = product(chars, repeat=length)
  58.     for i in it:
  59.         name = ''.join(i) + '.' + suffix
  60.         print(f'   {name}  checking...\r', end='')

  61.         res = check(name, sample, sample_fail, retry_rule)
  62.         if res == 'ok':
  63.             print(f'   {name}              ')
  64.             log(name)
  65.         elif res == 'unknown':
  66.             print(f'   {name}  [?]         ')
  67.             log(name+' [?]')

  68.     save and file.close()


  69. run(chars, length, suffix, sample, sample_fail)
複製代碼


回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 加入我們

本版積分規則

备案权重域名预定

QQ|4um創業社區

GMT+8, 2024-5-20 20:37

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回復 返回頂部 返回列表