我有域列表我想測試是他們的主域名或子域名或域名服務器或郵件服務器:如何測試域是'www'域還是子域或名稱服務器域或郵件域在python中?
- www.domain.com
- ns1.domain.com
- mail.domain.com
- community.domain.com
- mx.domain.com
- mx3.domain.com
- aspmx.l.google.com
- forums.domain.com
,我用tldextract Python庫
from tld import get_tld
import tldextract
class DomainOpt(object):
"""docstring for DomainOpt"""
_domainname = ''
_tldextract = None
_domaintype = ''
def __init__(self, domainname):
super(DomainOpt, self).__init__()
self._domainname = domainname
self._tldextract = tldextract.extract("http://%s/" % self._domainname)
if self._tldextract.subdomain == 'mail':
self._domaintype = 'maildomain'
elif self._tldextract.subdomain in ['ns1','ns2','ns3','ns4','ns5','ns6',
'ns7','ns8','ns9','ns10','ns11','ns12','ns13','ns14', 'ns15', 'ns16']:
self._domaintype = 'dnsdomain'
elif self._tldextract.subdomain is not None:
self._domaintype = 'subdomain'
else:
self._domaintype = 'domain'
@property
def domainname(self):
return get_tld(str('http://%s/' % self._domainname), fail_silently=True)
@property
def domain(self):
return self._tldextract.domain
@property
def subdomain(self):
return self._tldextract.subdomain
@property
def suffix(self):
return self._tldextract.suffix
@property
def domaintype(self):
return self._domaintype
它是什麼沒有做 '簡單' 的頂級域名?你得到什麼錯誤? – Withnail
這個列表中有許多種名稱服務器,但問題如何區分郵件域和名稱服務器和子域 –
domaintype始終是錯誤或錯誤 –