mirror of
https://github.com/adulau/DomainClassifier.git
synced 2024-12-23 00:55:58 +00:00
exclude and include methods added
exclude or include domains from a regular expression. If validdomain was called before, the exclude or include is on the validdomain list only.
This commit is contained in:
parent
ed376c89e0
commit
ed9a25d1b7
2 changed files with 45 additions and 3 deletions
|
@ -12,7 +12,7 @@ import socket
|
|||
__author__ = "Alexandre Dulaunoy"
|
||||
__copyright__ = "Copyright 2012, Alexandre Dulaunoy"
|
||||
__license__ = "AGPL version 3"
|
||||
__version__ = "0.0.1"
|
||||
__version__ = "0.0.2"
|
||||
|
||||
|
||||
|
||||
|
@ -27,6 +27,7 @@ class Extract:
|
|||
self.rawtext = rawtext
|
||||
self.presolver = dns.resolver.Resolver()
|
||||
self.presolver.nameservers = ['149.13.33.69']
|
||||
self.vdomain = []
|
||||
|
||||
"""__origin is a private function to the ASN lookup for an IP address via
|
||||
the Team Cymru DNS interface. ipadd is a string contain the IP address in a
|
||||
|
@ -68,6 +69,7 @@ class Extract:
|
|||
self.validdomain = set()
|
||||
else:
|
||||
self.validdomain = []
|
||||
|
||||
for domain in self.domain:
|
||||
for dnstype in rtype:
|
||||
try:
|
||||
|
@ -75,6 +77,7 @@ class Extract:
|
|||
except:
|
||||
pass
|
||||
else:
|
||||
self.vdomain.append(domain)
|
||||
if extended is False:
|
||||
self.validdomain.add((domain))
|
||||
else:
|
||||
|
@ -100,7 +103,43 @@ class Extract:
|
|||
if(orig == cc): self.localdom.append(dom)
|
||||
return self.localdom
|
||||
|
||||
def filterdomain(self,filter=None):
|
||||
pass
|
||||
"""exclude domains from a regular expression. If validdomain was called,
|
||||
it's only on the valid domain list."""
|
||||
|
||||
def exclude(self,expression=None):
|
||||
self.cleandomain = []
|
||||
|
||||
excludefilter = re.compile(expression)
|
||||
|
||||
if not self.vdomain:
|
||||
domains = self.domain
|
||||
else:
|
||||
domains = self.vdomain
|
||||
|
||||
for dom in domains:
|
||||
if excludefilter.search(dom):
|
||||
pass
|
||||
else:
|
||||
self.cleandomain.append(dom)
|
||||
return self.cleandomain
|
||||
|
||||
"""include domains from a regular expression. If validdomain was called,
|
||||
it's only on the valid domain list."""
|
||||
|
||||
def include(self,expression=None):
|
||||
self.cleandomain = []
|
||||
|
||||
includefilter = re.compile(expression)
|
||||
|
||||
if not self.vdomain:
|
||||
domains = self.domain
|
||||
else:
|
||||
domains = self.vdomain
|
||||
|
||||
for dom in domains:
|
||||
if includefilter.search(dom):
|
||||
self.cleandomain.append(dom)
|
||||
|
||||
return self.cleandomain
|
||||
|
||||
|
||||
|
|
|
@ -10,3 +10,6 @@ print "LU:"
|
|||
print c.localizedomain(cc='LU')
|
||||
print "BE:"
|
||||
print c.localizedomain(cc='BE')
|
||||
|
||||
print c.include(expression=r'\.lu$')
|
||||
print c.exclude(expression=r'\.lu$')
|
||||
|
|
Loading…
Reference in a new issue