我有要测试的域列表,它们是主域还是子域,名称服务器还是邮件服务器:
我使用了tldextractpython库
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
试试这个:
还要注意,这只适用于
com
、net
、org
等“简单”tldtldextract库的作用与您需要的相反:给定一个字符串“mail.example.com,它将返回“com”而不是“mail”。要做您需要的事情,您不需要任何库;只需在域名中搜索“.”并获取它前面的子字符串。你知道吗
相关问题 更多 >
编程相关推荐