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:
Alexandre Dulaunoy 2012-01-31 14:20:51 +01:00
parent ed376c89e0
commit ed9a25d1b7
2 changed files with 45 additions and 3 deletions

View file

@ -12,7 +12,7 @@ import socket
__author__ = "Alexandre Dulaunoy" __author__ = "Alexandre Dulaunoy"
__copyright__ = "Copyright 2012, Alexandre Dulaunoy" __copyright__ = "Copyright 2012, Alexandre Dulaunoy"
__license__ = "AGPL version 3" __license__ = "AGPL version 3"
__version__ = "0.0.1" __version__ = "0.0.2"
@ -27,6 +27,7 @@ class Extract:
self.rawtext = rawtext self.rawtext = rawtext
self.presolver = dns.resolver.Resolver() self.presolver = dns.resolver.Resolver()
self.presolver.nameservers = ['149.13.33.69'] self.presolver.nameservers = ['149.13.33.69']
self.vdomain = []
"""__origin is a private function to the ASN lookup for an IP address via """__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 the Team Cymru DNS interface. ipadd is a string contain the IP address in a
@ -68,6 +69,7 @@ class Extract:
self.validdomain = set() self.validdomain = set()
else: else:
self.validdomain = [] self.validdomain = []
for domain in self.domain: for domain in self.domain:
for dnstype in rtype: for dnstype in rtype:
try: try:
@ -75,6 +77,7 @@ class Extract:
except: except:
pass pass
else: else:
self.vdomain.append(domain)
if extended is False: if extended is False:
self.validdomain.add((domain)) self.validdomain.add((domain))
else: else:
@ -100,7 +103,43 @@ class Extract:
if(orig == cc): self.localdom.append(dom) if(orig == cc): self.localdom.append(dom)
return self.localdom return self.localdom
def filterdomain(self,filter=None): """exclude domains from a regular expression. If validdomain was called,
pass 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

View file

@ -10,3 +10,6 @@ print "LU:"
print c.localizedomain(cc='LU') print c.localizedomain(cc='LU')
print "BE:" print "BE:"
print c.localizedomain(cc='BE') print c.localizedomain(cc='BE')
print c.include(expression=r'\.lu$')
print c.exclude(expression=r'\.lu$')