domain_util.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. """
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2024/04/26
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc : 域名工具
  8. """
  9. import whois
  10. from concurrent.futures import ThreadPoolExecutor
  11. class DomainUtil(object):
  12. """域名工具"""
  13. def __init__(self):
  14. super(DomainUtil,self).__init__()
  15. @staticmethod
  16. def get_expiration_date(domain:str)->None:
  17. '''
  18. 检测域名是否快到期
  19. :params domain 域名:
  20. :return true or false'''
  21. try:
  22. whi = whois.whois(domain)
  23. expirationDate= whi.expiration_date
  24. return expirationDate
  25. except Exception as e:
  26. print(e)
  27. return None
  28. @staticmethod
  29. def is_available(domain: str)->None:
  30. '''
  31. 检测域名是否可用
  32. :params domain 域名:
  33. :return true or false'''
  34. try:
  35. whi = whois.whois(domain)
  36. return False
  37. except Exception as e:
  38. if(str(e).index("No match") == 0):
  39. return True
  40. else:
  41. return False