예제 #1
0
파일: dns.py 프로젝트: softsoft/concurrence
 def __init__(self, s=None, configtext=None):
     if s is None:
         flags = adns.iflags.noautosys | adns.iflags.noserverwarn | adns.iflags.noerrprint
         if configtext is None:
             s = adns.init(flags)
         else:
             s = adns.init(flags, sys.stderr, configtext)
     self._s = s
     self._queries = {}
     self._running = False
예제 #2
0
파일: dns.py 프로젝트: JoyTeam/concurrence
 def __init__(self, s=None, configtext=None):
     if s is None:
         flags = adns.iflags.noautosys | adns.iflags.noserverwarn | adns.iflags.noerrprint
         if configtext is None:
             s = adns.init(flags)
         else:
             s = adns.init(flags, sys.stderr, configtext)
     self._s = s
     self._queries = {}
     self._running = False
예제 #3
0
    def __init__(self, resolv_conf=None):
        if resolv_conf:
            self.resolver = adns.init(
                adns.iflags.noautosys + adns.iflags.noerrprint,
                sys.
                stderr,  # FIXME: adns version 1.2.2 will allow keyword params
                resolv_conf)
        else:
            self.resolver = adns.init(adns.iflags.noautosys +
                                      adns.iflags.noerrprint)

        self._queries = {}  # keeps query objects alive
예제 #4
0
 def _setUp(self, nameserver="127.0.0.1"):
     '''Setup'''
     self.daemon.stop()
     self.release = testlib.ubuntu_release()
     self.dns = adns.init(adns.iflags.noautosys, sys.stderr,
                          'nameserver ' + nameserver)
     self.daemon.start()
예제 #5
0
파일: IPInfo.py 프로젝트: dmwm/overview
  def __init__(self, cachedir = None,
               gip = None, psl = None, res = None,
               maxtime = 30, maxtries = 3):
    """Constructor.

    Initialises the lookup object so it is ready for queries.

    @param cachedir -- Default location for caching databases, used if
    `gip` or `psl` have not been specified. If unset and neither `gip`
    nor `psl` arguments are provided, the databases are cached in the
    current directory.

    @param gip -- Reference to GeoIPLookup object. If None, a new
    object is created, using `cachedir` or current directory as the
    location for the city database file.

    @param psl -- Reference to PublicSuffixLookup object. If None, a
    new object is created, using `cachedir` or current directory as
    the location for the YAML cache database.

    @param res -- Reference to adns DNS resolver object. If None, a
    new resolver is created. If you want to use a nameserver other
    than your system default one, pass in custom adns object created
    with the appropriate "nameserver x.y.z.w" resolver argument.

    @param maxtime -- The maximum time to wait for DNS replies. Some
    DNS servers are slow to respond so some queries take a long time
    to complete, or will simply time out. If the client is submitting
    large numbers of addresses for query, the stragglers are handled
    automatically and there is no reason to reduce the query time-out.
    However if the client has just a few addresses to resolve, or is
    in a hurry to get the answer, set `maxtime` to some smaller value.

    @param maxtries -- The maximum number of times to attempt main
    queries per IP address. In general this value should be greater
    than one to avoid failures resulting from dropped DNS packets and
    to catch straggler responses from slow, far away and somewhat
    misconfigured DNS servers. More than three rarely improves the
    accuracy of the results.
    """
    now = time()
    self.maxtime = maxtime
    self.maxtries = maxtries
    geopath = (cachedir and "%s/GeoLiteCity.dat" % cachedir)
    pslpath = (cachedir and "%s/psl.yml" % cachedir)
    self.res = res or adns.init(adns.iflags.noautosys)
    debug("IP2INFO", 2, "dns resolver initialised %.2f", time() - now)
    self.gip = gip or GeoIPLookup(path = geopath)
    debug("IP2INFO", 2, "geoip resolver initialised %.2f", time() - now)
    self.psl = psl or PublicSuffixLookup(path = pslpath)
    debug("IP2INFO", 2, "domain resolver initialised %.2f", time() - now)
    self.ptrfail = set()
    self.ptrmap = {}
    self.asnmap = self._asninit()
    self.queries = {}
    self.ipaddrs = {}
    self.notify = {}
    self.resstat = {}
    debug("IP2INFO", 1, "initialisation complete %.2f", time() - now)
예제 #6
0
 def __init__(self, hosts, intensity=100):
     """
     hosts: a list of hosts to resolve
     intensity: how many hosts to resolve at once
     """
     self.hosts = hosts
     self.intensity = intensity
     self.adns = adns.init(adns.iflags.noautosys,sys.stderr, "nameserver 8.8.8.8")
예제 #7
0
 def __init__(self, hosts, intensity=100):
     """
     hosts: a list of hosts to resolve
     intensity: how many hosts to resolve at once
     """
     self.hosts = hosts
     self.intensity = intensity
     self.adns = adns.init()
예제 #8
0
 def __init__(self, hosts, intensity=100):
     """
     hosts: a list of hosts to resolve
     intensity: how many hosts to resolve at once
     """
     self.hosts = hosts
     self.intensity = intensity
     self.adns = adns.init()
예제 #9
0
 def __init__(self, callback, max_reqs=100):
     self.adns = adns.init()
     self.collect_results_thread = threading.Thread(target=self.collect_results)
     self.resolver_thread = threading.Thread(target=self.resolver)
     self.active = False
     self.active_queries = {}
     self.total_processed = 0
     self.callback = callback
     self.queue = Queue()
     self.max_reqs = threading.Semaphore(max_reqs)
    def __init__(self, host, port, username, password, debug = False):
        self.host = host
        self.port = port
        self._debug = debug

        if username and password:
            password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
            url = 'http://%s:%d/transmission/rpc' % (host, port)
            password_mgr.add_password(None, url, username, password)
            authhandler = urllib2.HTTPBasicAuthHandler(password_mgr)
            opener = urllib2.build_opener(authhandler)
            urllib2.install_opener(opener)

        # check rpc version
        request = TransmissionRequest(host, port, 'session-get', self.TAG_SESSION_GET)
        request.send_request()
        response = request.get_response()
        
        # rpc version too old?
        version_error = "Unsupported Transmission version: " + str(response['arguments']['version']) + \
            " -- RPC protocol version: " + str(response['arguments']['rpc-version']) + "\n"

        min_msg = "Please install Transmission version " + self.TRNSM_VERSION_MIN + " or higher.\n"
        try:
            if response['arguments']['rpc-version'] < self.RPC_VERSION_MIN:
                raise TransmissionException(version_error + min_msg)
        except KeyError:
            raise TransmissionException(version_error + min_msg)

        # rpc version too new?
        if response['arguments']['rpc-version'] > self.RPC_VERSION_MAX:
            raise TransmissionException(version_error + "Please install Transmission version " + self.TRNSM_VERSION_MAX + " or lower.\n")


        # set up request list
        self.requests = {'torrent-list':
                             TransmissionRequest(host, port, 'torrent-get', self.TAG_TORRENT_LIST, {'fields': self.LIST_FIELDS}),
                         'session-stats':
                             TransmissionRequest(host, port, 'session-stats', self.TAG_SESSION_STATS, 21),
                         'session-get':
                             TransmissionRequest(host, port, 'session-get', self.TAG_SESSION_GET),
                         'torrent-details':
                             TransmissionRequest(host, port)}

        self.torrent_cache = []
        self.status_cache  = dict()
        self.torrent_details_cache = dict()
        self.hosts_cache   = dict()
        self.geo_ips_cache = dict()
        if features['dns']:   self.resolver = adns.init()
        if features['geoip']: self.geo_ip = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)

        # make sure there are no undefined values
        self.wait_for_torrentlist_update()
예제 #11
0
 def __init__(self, host, port, flags=None):
     Process.__init__(self)
     self.adns_state = adns.init()
     self.ip_cache = {}
     self.host_cache = {}
     # self._workload = threading.Condition()
     self._workload = flags[0] if flags and len(flags) > 0 else \
         threading.Condition()
     self.host = host
     self.port = port
     # self._stop = threading.Event()
     self._stop = flags[1] if flags and len(flags) > 1 else threading.Event()
     self._prints = flags[2] if flags and len(flags) > 2 else True
예제 #12
0
 def __init__(self, host, port, flags=None):
     Process.__init__(self)
     self.adns_state = adns.init()
     self.ip_cache = {}
     self.host_cache = {}
     # self._workload = threading.Condition()
     self._workload = flags[0] if flags and len(flags) > 0 else \
         threading.Condition()
     self.host = host
     self.port = port
     # self._stop = threading.Event()
     self._stop = flags[1] if flags and len(flags) > 1 else threading.Event(
     )
     self._prints = flags[2] if flags and len(flags) > 2 else True
    def setUp(self):
        '''Setup mechanisms'''
        DnsmasqCommon._setUp(self)

        self.dns = adns.init(adns.iflags.noautosys, sys.stderr,
                             'nameserver 127.0.0.1')

        # Allow for opendns on the network...
        testlib.config_replace(self.config, "", True)
        subprocess.call([
            'sed', '-i', 's,^#bogus-nxdomain=.*,bogus-nxdomain=' +
            testlib.bogus_nxdomain + ',g', self.config
        ])

        self.daemon.start()
예제 #14
0
    def __init__(self, hostsfile,hostIPfile,intensity=100,nameserver='202.96.199.133'):
        ''' 
        hostsfile: file of hosts waiting to be resolved
	hostIPfile: file of hosts and their IPs 
        intensity: how many hosts to resolve at once
	nameserver: dns server
        '''

        self.hosts = open(hostsfile)
	self.hostIP = open(hostIPfile,'a')
        self.intensity = intensity
        #self.adns = adns.init(adns.iflags.noautosys,sys.stderr,"nameserver 202.96.199.133")
        self.adns = adns.init(adns.iflags.noautosys,sys.stderr,"nameserver "+nameserver)
	self.hostCnt=0
	self.ipCnt=0
def main():
    # logger = threading.log_to_stderr()
    # logger.setLevel(logging.INFO)
    f = open("/home/edward/Projects/test_python_adns/top-1m.csv", "r")
    urls = [line.split(',')[1].strip() for line in f.readlines()]
    f.close()
    num = 500
    # Put urls into queue
    urls = urls[:num]
    q = Queue.Queue()
    count = 0
    for each in urls:
        q.put(each)
        count += 1
    print count
    print q.qsize()
    # other initialization
    resolved_list = []
    start_flag = threading.Event()
    adns_state = adns.init()
    new_job = threading.Condition()
    # build process pools
    opts = {"start": start_flag, "jobs": q, "adns": adns_state, "notify": new_job}
    pool = [WorkerProcess(opts) for i in xrange(1)]
    for each in pool:
        each.start()

    start_flag.set()


    while True:
        with new_job:
            # TODO: Figure out why adns library crashed even with a lock
            # It is not successfully passed into threads
            for query in adns_state.completed():
                answer = query.check()
                resolved_list.append(answer)
                print answer
            new_job.wait()
        if len(resolved_list) == count:
            break

    for each in pool:
        each.join()
예제 #16
0
def resolve_all(source, buffer=10):
    s = iter(source)
    c = adns.init()
    q = deque()

    def put():
        req = next(s)
        q.append(c.submit(*req))

    try:
        for x in range(0, buffer):
            put()

        while True:
            put()
            yield q.popleft().wait()

    except StopIteration:
        for x in q:
            yield x.wait()
예제 #17
0
파일: massdns.py 프로젝트: hoangth/massdns
def resolve_all(source, buffer = 10):
	s = iter(source)
	c = adns.init()
	q = deque()

	def put():
		req = next(s)
		q.append(c.submit(*req))

	try:
		for x in range(0,buffer):
			put()

		while True:
			put()
			yield q.popleft().wait()

	except StopIteration:
		for x in q:
			yield x.wait()
def main():
    logger = multiprocessing.log_to_stderr()
    logger.setLevel(logging.INFO)
    f = open("/home/edward/Projects/test_python_adns/top-1m.csv", "r")
    urls = [line.split(',')[1].strip() for line in f.readlines()]
    f.close()
    num = 500
    # Put urls into queue
    urls = urls[:num]
    q = multiprocessing.Queue()
    count = 0
    for each in urls:
        q.put(each)
        count += 1
    print count
    print q.qsize()
    # other initialization
    resolved_list = []
    start_flag = multiprocessing.Event()
    c = adns.init()
    new_job = multiprocessing.Condition()
    # build process pools
    opts = {"start": start_flag, "jobs": q, "adns": c, "notify": new_job}
    pool = [WorkerProcess(opts) for i in xrange(1)]
    for each in pool:
        each.start()

    start_flag.set()

    while True:
        with new_job:
            for query in c.completed():
                answer = query.check()
                resolved_list.append(answer)
                print answer
            new_job.wait()
        if len(resolved_list) == count:
            break

    for each in pool:
        each.join()
예제 #19
0
 def setUp(self):
     self.resolver = adns.init()
예제 #20
0
    verbose = False
    maxcons = 1000


#### State ####

dns_cache = {}  # {host : ip}
adns_queries = {}  # {query : context}
connections = {}  # {fileno : context}
statistics = {}  # {Error : count}
epoll = select.epoll()
queue = Queue()
timers = []
global current
current = None
resolver = adns.init(adns.iflags.noautosys)

#### Exeptions ####


class ConnectionError(Exception):
    pass


class TimeoutError(ConnectionError):
    pass


class ConnectError(ConnectionError):
    pass
예제 #21
0
 def setUp(self):
   self.resolver = adns.init()
예제 #22
0
    def __init__(self, hostfile, total_count, skip_count, method, path,
                 useragent, append_headers, noredirects, nossl, timeout,
                 clients, quiet, statuscodes):

        self.hostfile = hostfile
        self.total_count = total_count
        self.skip_count = skip_count
        self.method = method
        self.path = path
        self.useragent = useragent
        self.append_headers = None
        if append_headers:
            self.append_headers = ''
            for header in append_headers:
                self.append_headers += header + '\r\n'
        self.noredirects = noredirects
        self.nossl = nossl
        self.timeout = timeout
        self.numclients = clients
        self.batch_count = self.numclients
        self.quiet = quiet
        self.statuscodes = statuscodes

        self.re_ipaddr = re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$')
        self.cut_count = 10000

        self.resolver = adns.init(
            adns.iflags.noautosys)  # TODO: what does this flag mean?
        self.pending_requests = {}
        self.queries = {}
        self.requests = collections.deque()
        self.recent_requests = []
        self.recent_requests_max = 101
        self.recent_requests_count = 0
        for i in range(0, self.recent_requests_max):
            self.recent_requests.append('')

        if hostfile.endswith('.zip'):
            zfile = zipfile.ZipFile(hostfile, 'r')
            zi = zfile.infolist()
            if 1 == len(zi):
                self.infile = zfile.open(zi[0], 'r')
            else:
                raise Exception('unable to determine file in zipfile')
        elif hostfile.endswith('.bz2'):
            self.infile = bz2.BZ2File(hostfile, 'r')
        else:
            self.infile = open(hostfile, 'r')

        self.request_generator = BatchedReader(self.infile, self.process_line,
                                               self.batch_count,
                                               self.total_count,
                                               self.skip_count)

        socket.setdefaulttimeout(max(5, self.timeout - 5))

        self.clients = []
        for i in range(0, self.numclients):
            self.clients.append(
                Client(self.method, self.useragent, self.append_headers,
                       self.quiet, self.statuscodes))
예제 #23
0
#!/usr/bin/python
#Author: DiabloHorn
#Adjusted/borrowed code from:
#   http://michael.susens-schurter.com/code/easyadns/try4.py
#   http://www.catonmat.net/blog/asynchronous-dns-resolution/

import sys
import os
import time
import adns
import re
from bs4 import BeautifulSoup 
import requests
dodebug = False
pending = dict()
resolver = adns.init()
ARECORD = adns.rr.A
ipdict={}
def usage():
    print '\033[1;35;40m'
    print "#######################################"
    print "This tools developed for Apt hackers"
    print "search domains ip,and the neighbor"
    print "author:[email protected]"
    print 'Ex: ' + sys.argv[0] + ' domains.txt'
    print "#######################################"
    print '\033[0m'
    sys.exit()

def submitquery(queryname,querytype):
    sbmqry = resolver.submit(name, querytype)
예제 #24
0
 def __init__(self, s=None):
     self._s = s or adns.init(adns.iflags.noautosys)
     self._queries = {}
예제 #25
0
파일: askmail.py 프로젝트: celer/ask
	def	smtp_validate(self, email, helo_domain = None, envelope_from = None):
		"""
		This method validates a given email address by connecting to the MX servers
		and attempting an initial handshake with the SMTP server. First, we request
		an email to an invalid name. If the server returns 2xx, we understand that
		this server says OK for all cases and return valid. Then, we try our real
		email. If the server returns 5xx, we return "invalid". Any error condition
		results in a "valid" response (meaning that we cannot validate the address
		using an MX query).
		"""

		## Import DNS class. If not found, try ADNS class.

		dnsclass  = 0
		adnsclass = 0

		try:
 			import DNS
			adnsclass = 0
			dnsclass  = 1
		except:
 			self.log.write(1, "  smtp_validate: Cannot import DNS class. Trying ADNS...")

		if not dnsclass:
			try:
				import adns
				adnsclass = 1
				dnsclass  = 0
			except:
				self.log.write(1, "  smtp_validate: Cannot import ADNS class. Feature disabled.")
				return -1

		import smtplib

		## Parse down the email in email and domain

		res = re.match("(.+)@(.+)", email)

		if res:
			username = res.group(1)
			domain   = res.group(2)
		else:
			self.log.write(1, "  smtp_validate: Cannot parse email")
			return -1

		self.log.write(5, "  smtp_validate: user=%s, domain=%s" % (username, domain))

		## Default HELO and ENVELOPE from are the username/domain

		if not helo_domain:
			helo_domain = domain

		if not envelope_from:
			envelope_from = email

		## Retrieve list of MX records and attempt one by one, sorted by priority

		if dnsclass:
			self.log.write(10, "  smtp_validate: Using DNS class")
			dnsobj = DNS.Request(DNS.ParseResolvConf())
			answer = DNS.mxlookup(domain)
			del(dnsobj)
		else:
			self.log.write(10, "  smtp_validate: Using ADNS class")
			s = adns.init()
			(status, cname, expires, answer) = s.synchronous(domain,adns.rr.MXraw)
			del(s)

		mxlist = []
		for (mxpri, mxhost) in answer:
			mxlist.append((mxpri, mxhost))
		mxlist.sort()
		
		for (mxpri, mxhost) in mxlist:
			self.log.write(5, "  smtp_validate: Attempting MX server %s, priority %s" % (mxhost, mxpri))

			## Initial Connection
			try:
				server = smtplib.SMTP(mxhost)
				server.set_debuglevel(0)
			except:
				self.log.write(5, "  smtp_validate: Could not connect to %s" % domain)
				continue

			## Establish the SMTP connection the usual way, then try an "RCPT TO"
			## to an invalid user name. If it says 2xx, we assume this MX says 2xx
			## for everyone and return "valid".

			invalidmail = "askprobe%d@%s" % (int(time.time()), domain)

			cmds = [ 
				("HELO %s"         % helo_domain,		200, 299, -1),
				("MAIL FROM: <%s>" % envelope_from, 	200, 299, -1),
				("RCPT TO: <%s>"   % invalidmail,       500, 599, 1),
				("RCPT TO: <%s>"   % email,             200, 299, 0),
				#("QUIT",                               999, 999, 0)	## Invalid if it got here
			]

			for (cmd, minret, maxret, retcode) in cmds:
					
				self.log.write(10, "  smtp_validate: Sending %s" % cmd)

				try:
					ret = server.docmd(cmd)
				except smtplib.SMTPServerDisconnected:
					self.log.write(5, "  smtp_validate: SMTP server disconnected.")
					break
					
				if ret[0] < minret or ret[0] > maxret:

					self.log.write(1, "  smtp_validate: Command=%s, SMTP code=%d, return=%d" % (cmd, ret[0], retcode))

					if retcode != -1:
						try:
							server.docmd("QUIT")
						except smtplib.SMTPServerDisconnected:
							pass

						del(server)
						return (retcode)
					else:
						break
				else:
					self.log.write(1, "  smtp_validate: Returned SMTP code=%d" % ret[0])

		## Getting here means we couldn't get a satisfactory
		## answer from any of the MX servers

		return -1
예제 #26
0
파일: MXRecord.py 프로젝트: dotse/Mailcheck
	def run(self):
		domain = self.getInput('domain')

		self.result.info('Starting MX record lookup against %s', (domain))
		dns = adns.init()
		mxRecords = dns.synchronous(domain, adns.rr.MX)
		records = []
		if (len(mxRecords[3]) >= 1):

			for i in mxRecords[3]:
				prio = str(i[0])
				host = i[1][0]
				ipv = get_ipv_type(host)
				if len(ipv) <= 2:
					if self.logger:
						self.logger.debug("Failed to find IPv type for host \"%s\"" % host)
					continue
				if self.logger:
					self.logger.debug("Host: %s, Prio: %s, IPv: %s" % (host, prio, ipv))

				records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
						'connection_type': ipv[1]})
				self.result.info('Found host %s (%s), priority %s', (host, ipv[2], prio))
				if (ipv[1] == "INET6"):
					ipv = get_ipv_type(host, "INET")
					if (ipv[2] != None):
						records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
							'connection_type': ipv[1]})
						self.result.info('Found host %s (%s), priority %s', (host, ipv[2], prio))
		else:
			prio = "-1"
			host = domain
			ipv = get_ipv_type(host)
			if len(ipv) != 0:
				records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
					'connection_type': ipv[1]})
				self.result.info('Found host %s (%s), priority %s', (host, ipv[2], prio))
				if (ipv[1] == "INET6"):
					ipv = get_ipv_type(host, "INET")
					if (ipv[2] != None):
						records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
							'connection_type': ipv[1]})
						self.result.info('Found no MX-record, using host %s (%s)', \
								(host, ipv[2]))

		message = ""
		code = Plugin.STATUS_OK
		if len(records) == 0:
			message = 'No records found'
			code = Plugin.STATUS_ERROR
			self.result.error(message)
		elif len(records) == 1 and records[0]['prio'] == "-1" and self.isChild != 0:
			message = 'No MX-records found, using A/AAAA-record'
			code = Plugin.STATUS_OK
			self.result.info(message)
		elif len(records) == 1 and records[0]['prio'] == "-1" and self.isChild == 0:
			message = 'No MX-records found, using A/AAAA-record'
			code = Plugin.STATUS_WARNING
			self.result.warning(message)
		elif len(records) == 1 and records[0]['connection_type'] == "INET6" \
				and self.isChild == 0:
			message = 'Only IPv6 addresses found, this might cause delivery problems'
			code = Plugin.STATUS_WARNING
			self.result.warning(message)
		elif len(records) == 1 and self.isChild == 0:
			message = 'Only one record found, two or more is recommended'
			code = Plugin.STATUS_OK
			self.result.info(message)
		else:
			message = 'Multiple MX-records found'
			code = Plugin.STATUS_OK
			self.result.info(message)

		self.result.extra('more info mx record', type='adv')

		self.result.info('Finished MX record lookup against %s', (domain))

		# Output
		if len(records) == 0:
			self.result.setOutput(None)
		else:
			self.result.setOutput({'mx_record': records}, persist=True)

		self.result.setTestStatus(code)
예제 #27
0
      # Get application (process) name, if the user didn't specify one.
      if self._application is None or len(self._application) == 0:
         self._application = sys.argv[0] if len(sys.argv[0]) > 0 else 'unknown'

      self._host, self._port = self._parseHostPort(server if server is not None else self._default_server)
   
      # Get system hostname.
      try:
         self._hostname = socket.gethostname()
      except Exception, ex:
         warnings.warn("Could not determine system hostname: %s" % ex, RuntimeWarning, 2)
         self._hostname = "unknown"
      
      if adns is not None:
         self._adns_resolver = adns.init()
      else:
         self._adns_resolver = None
      self._adns_query = None
      
      # Check if we were given an IP address instead of a hostname.
      try:
         socket.inet_aton(self._host)
         self._sockaddrs = [(self._host, self._port)]
      except socket.error: 
         # Otherwise, fire off an asynchronous DNS query now to resolve it.
         # We do this so _send() doesn't have to block.
         self._queryDNS()

   def __del__(self):
      # Attempt to flush the buffer, if any exists.
예제 #28
0
	def run(self):
		pluginName = self.__class__.__name__
		testId = self.getInput('testId')
		email = self.getInput('email')
		mx = self.getInput('MXRecord')
		dns = adns.init()
		
		records = []
		raw = []
		resolves = []
		highestPrio = 0

		port = 25

		self.result.info('Started open relay test')

		failedTests = {}
		myhostname = socket.getfqdn()

		relayTestsCount = 0
		testnr = 1;
		nrMXRecords = len(mx[1]);
		for row in mx[1]:
			host = row[1]
			ip = row[2]
			type = row[3]

			failedTests[host] = []
			try:
				s = connect_to_host(host,port, type)
				data = s.recv(1024)
			except Exception, e:
				self.result.warning('Failed to connect to %s (%s)', (host,ip))
				continue
			
			self.result.info('Starting open relay tests against %s', host)
			
			mailfrom=[]
			mailrcpt=[]

			mailfrom.append("<spamtest@" + myhostname + ">")
			mailrcpt.append("<relaytest@" + myhostname + ">")
			mailfrom.append("<spamtest@" + myhostname + ">")
			mailrcpt.append("relaytest@" + myhostname + "")
			mailfrom.append("<spamtest>")
			mailrcpt.append("<relaytest@" + myhostname + ">")
			mailfrom.append("<>")
			mailrcpt.append("<relaytest@" + myhostname + ">")
			mailfrom.append("<spamtest@" + host + ">")
			mailrcpt.append("<relaytest@" + myhostname + ">")
			mailfrom.append("<spamtest@[" + ip + "]>")
			mailrcpt.append("<relaytest@" + myhostname + ">")
			mailfrom.append("<spamtest@" + host + ">")
			mailrcpt.append("<relaytest%" + myhostname + "@" + host + ">")
			mailfrom.append("<spamtest@" + host + ">")
			mailrcpt.append("<relaytest%" + myhostname + "@[" + ip + "]>")
			mailfrom.append("<spamtest@" + host + ">")
			mailrcpt.append("<\"relaytest@" + myhostname + "\">")
			mailfrom.append("<spamtest@" + host + ">")
			mailrcpt.append("<\"relaytest%" + myhostname + "\">")
			mailfrom.append("<spamtest@" + host + ">")
			mailrcpt.append("<relaytest@" + myhostname + "@" + host + ">")
			mailfrom.append("<spamtest@" + host + ">")
			mailrcpt.append("<\"relaytest@" + myhostname + "\"@" + host + ">")
			mailfrom.append("<spamtest@" + host + ">")
			mailrcpt.append("<relaytest@" + myhostname + "@[" + ip + "]>")
			mailfrom.append("<spamtest@" + host + ">")
			mailrcpt.append("<@" + host + ":relaytest@" + myhostname + ">")
			mailfrom.append("<spamtest@" + host + ">")
			mailrcpt.append("<@[" + ip + "]:relaytest@" + myhostname + ">")
			mailfrom.append("<spamtest@" + host + ">")
			mailrcpt.append("<" + myhostname + "!relaytest>")
			mailfrom.append("<spamtest@" + host + ">")
			mailrcpt.append("<" + myhostname + "!relaytest@" + host + ">")
			mailfrom.append("<spamtest@" + host + ">")
			mailrcpt.append("<" + myhostname + "!relaytest@[" + ip + "]>")
			mailfrom.append("<spamtest@" + host + ">")
			mailrcpt.append("<relaytest%[" + myhostname + "]@>")
			mailfrom.append("<spamtest@" + host + ">")
			mailrcpt.append("<relaytest@[" + myhostname + "]@>")
			relayTestsCount = len(mailfrom)

			try:
				result
			except:
				result=[]

			for testno in range(len(mailfrom)):
				self.livefeedback.message(testId, '%s, running subtest %s of %s on server %s (%s/%s)', (pluginName, (testno + 1), len(mailfrom), host, testnr, nrMXRecords))
				test=[
					[
						'HELO ' + host + '\r\n',
						'RSET\r\n',
						'MAIL FROM: ' + mailfrom[testno] + '\r\n',
						'RCPT TO: ' + mailrcpt[testno] + '\r\n'
					], [
						'250',
						'250 2.0.0 Ok|250 2.1.5 Flushed.*',
						'250 2.1.0 Ok',
						'250 2.1.0 Ok'
					], [
						'554.*|501.*|503.*|553.*|550.*|555.*|401.*|454.*'
					]
				]

				testlog=""

				for row in range(len(test[1])):
					exit_code=int()
					send=test[0][row]
					recv=test[1][row]
					
					try:		
						s.send(send)
					except Exception, e:
						if e[0] == 104:
							self.result.info("Warning connection reset by peer..")
						if e[0] == 32:
							self.result.info("Warning broken pipe, aborting subtest..")
							s = connect_to_host(host, port, type)
							#continue
					testlog += ">>> " + send

					try:		
						data = s.recv(1024)
					except Exception, e:
						if e[0] == 104:
							self.result.info("Warning connection reset by peer..")
						if e[0] == 32:
							#self.result.info("Warning broken pipe, aborting subtest..")
							s = connect_to_host(host, port, type)
							#continue

					testlog += "<<< " + data

					if not match(recv, data):
						if not match(test[2][0], data):
							exit_code=1
					elif row == (len(test[0]) - 1):
						exit_code=0

		
					if exit_code == 0 and row == (len(test[0]) - 1):
						self.result.info('Test %s on host %s:\n%s', ((testno + 1), host, testlog))
					elif exit_code == 1 and row == (len(test[0]) - 1):
						self.result.warning('Test %s FAILED on %s:\n%s', ((testno + 1), host, testlog), 'adv')
						failedTests[host].append(testno+1)
						failed=1
예제 #29
0
파일: IPInfo.py 프로젝트: dmwm/overview
    if isinstance(i, HostInfo):
      print "host=%s names=%s addrs=%s ipaddrs=%d ip=%s [%s]%s" % \
        (i.hostname, i.all_names, i.all_addrs, len(i.ipaddrs),
         origin.ip, origin.cidr, (not remain and " last notification") or "")
      i = origin
    print "%-40s %-10s %-6s %-25s %-18s %s %s %s %s" % \
      ("ip=%s [%s]" % (i.ip, i.cidr),
       "asn=%s,%s" % (i.asn.cc, i.asn.asn),
       "cc=%s" % i.geoip.cc,
       "domain=%s" % i.domain,
       "pos=%s" % ((i.geoip.lat != None and "%.4f,%.4f" % (i.geoip.lat, i.geoip.long)) or ""),
       "name=%s cidrname=%s wildname=%s" % (i.hostname, i.cidrhost, i.wildhost),
       "loc=%s" % ", ".join(x for x in (i.geoip.country, i.geoip.region, i.geoip.city) if x != None),
       "org=%s desc=%s" % (i.asn.org, i.asn.desc),
       "host=%s" % ", ".join(h.hostname for h in i.hosts))

  ns = nameservers[0][0]
  if ns == None:
    res = adns.init(adns.iflags.noautosys)
  else:
    res = adns.init(adns.iflags.noautosys, sys.stderr, "nameserver %s" % ns)

  x = IPResolver(res = res)
  x.submit(sys.argv[2:], kind=sys.argv[1], callback=report)
  x.wait()

  resstat = x.statistics()
  for key in sorted(resstat.keys()):
    status, name = key
    debug("STATS", 1, " %7d %s (%s)", resstat[key], name, status)
예제 #30
0
#!/usr/bin/python
#Author: DiabloHorn
#Adjusted/borrowed code from:
#   http://michael.susens-schurter.com/code/easyadns/try4.py
#   http://www.catonmat.net/blog/asynchronous-dns-resolution/

import sys
import time
import adns

dodebug = False
pending = dict()
resolver = adns.init()
ARECORD = adns.rr.A

def usage():
    print 'DiabloHorn http://diablohorn.wordpress.com'
    print 'Mass Resolve name2ip (Arecord)'
    print sys.argv[0] + ' <filename>'
    print 'cat <filename> | ' + sys.argv[0]
    sys.exit()

def submitquery(queryname,querytype):
    sbmqry = resolver.submit(name, querytype)
    pending[sbmqry] = name         
    
if __name__ == "__main__":   
    inputdata = None
    if len(sys.argv) == 1:
        #check if we are running interactively
        if sys.stdin.isatty():
예제 #31
0
파일: rspider.py 프로젝트: Averroes/raft
    def __init__(
        self,
        hostfile,
        total_count,
        skip_count,
        method,
        path,
        useragent,
        append_headers,
        noredirects,
        nossl,
        timeout,
        clients,
        quiet,
        statuscodes,
    ):

        self.hostfile = hostfile
        self.total_count = total_count
        self.skip_count = skip_count
        self.method = method
        self.path = path
        self.useragent = useragent
        self.append_headers = None
        if append_headers:
            self.append_headers = ""
            for header in append_headers:
                self.append_headers += header + "\r\n"
        self.noredirects = noredirects
        self.nossl = nossl
        self.timeout = timeout
        self.numclients = clients
        self.batch_count = self.numclients
        self.quiet = quiet
        self.statuscodes = statuscodes

        self.re_ipaddr = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
        self.cut_count = 10000

        self.resolver = adns.init(adns.iflags.noautosys)  # TODO: what does this flag mean?
        self.pending_requests = {}
        self.queries = {}
        self.requests = collections.deque()
        self.recent_requests = []
        self.recent_requests_max = 101
        self.recent_requests_count = 0
        for i in range(0, self.recent_requests_max):
            self.recent_requests.append("")

        if hostfile.endswith(".zip"):
            zfile = zipfile.ZipFile(hostfile, "r")
            zi = zfile.infolist()
            if 1 == len(zi):
                self.infile = zfile.open(zi[0], "r")
            else:
                raise Exception("unable to determine file in zipfile")
        elif hostfile.endswith(".bz2"):
            self.infile = bz2.BZ2File(hostfile, "r")
        else:
            self.infile = open(hostfile, "r")

        self.request_generator = BatchedReader(
            self.infile, self.process_line, self.batch_count, self.total_count, self.skip_count
        )

        socket.setdefaulttimeout(max(5, self.timeout - 5))

        self.clients = []
        for i in range(0, self.numclients):
            self.clients.append(Client(self.method, self.useragent, self.append_headers, self.quiet, self.statuscodes))
예제 #32
0
    def run(self):
        testId = self.getInput('testId')
        records = self.getInput('MXRecord')
        pluginName = self.__class__.__name__
        ipregexp = compile(r'^([0-9]*).([0-9]*).([0-9]*).([0-9]*)$')

        res = adns.init()

        blacklist = []
        blacklist.append(("multi.uribl.com", "http://uribl.com"))
        blacklist.append(("dsn.rfc-ignorant.org", "http://rfc-ignorant.org"))
        blacklist.append(("dul.dnsbl.sorbs.net", "http://www.au.sorbs.net"))
        blacklist.append(("sbl-xbl.spamhaus.org", "http://spamhaus.org"))
        blacklist.append(("bl.spamcop.net", "http://spamcop.net"))
        blacklist.append(("dnsbl.sorbs.net", "http://www.au.sorbs.net"))
        blacklist.append(("cbl.abuseat.org", "http://abuseat.org"))
        blacklist.append(
            ("ix.dnsbl.manitu.net", "http://www.dnsbl.manitu.net"))
        blacklist.append(("combined.rbl.msrbl.net", "http://msrbl.net"))
        blacklist.append(
            ("rabl.nuclearelephant.com", "http://nuclearelephant.com"))

        self.result.info('Starting Blacklist-test')

        if len(records['mx_record']) <= 0:
            result.error('Test could not be executed')

        results = []
        statusCounts = {
            Plugin.STATUS_OK: 0,
            Plugin.STATUS_WARNING: 0,
            Plugin.STATUS_ERROR: 0
        }

        for record in records['mx_record']:
            host = record['host']
            ip = record['ip']
            blacklistip = sub(ipregexp, r'\4.\3.\2.\1', ip)

            code = Plugin.STATUS_OK
            reply_code = reply_msg = None
            try:
                for cbl in blacklist:
                    url = cbl[1]
                    cbl = cbl[0]

                    cblhost = str(blacklistip + "." + cbl)
                    self.livefeedback.message(testId, "%s, subtest: %s in %s?",
                                              (pluginName, ip, cbl))
                    try:
                        addr = res.synchronous(cblhost, adns.rr.A)
                        reply_code = addr[3][0]
                        msg = res.synchronous(cblhost, adns.rr.TXT)
                        reply_msg = msg[3][0][0]
                    except:
                        pass

                    # Add status message
                    if (match(ipregexp, str(reply_code))):
                        self.result.warning(
                            '%s (%s) is listed on blacklist %s, result: %s, text: %s.',
                            (ip, host, cbl, reply_code, reply_msg))
                        self.result.extra(
                            '<a href="%s" target="_blank">%s</a>' % (url, url),
                            type='all')
                    else:
                        self.result.info(
                            '%s (%s) is not listed on blacklist %s.',
                            (ip, host, cbl))
                        self.result.extra(
                            '<a href="%s" target="_blank">%s</a>' % (url, url),
                            type='adv')

                    results.append([host, ip, cblhost, reply_code, reply_msg])
                    statusCounts[code] += 1
            except:
                pass

        # Figure the final status of the test
        code = Plugin.STATUS_OK
        if statusCounts[Plugin.STATUS_WARNING] > 0 and statusCounts[
                Plugin.STATUS_WARNING] == len(results):
            code = Plugin.STATUS_ERROR
            self.result.error('All Blacklist-tests failed!')

        self.result.extra('more info blacklists', type='adv')
        self.result.info('Finished Blacklist-test')
        self.result.setTestStatus(code)
    def setUp(self):
        '''Setup mechanisms'''

        self.options_file = "/etc/bind/named.conf.options"
        if self.lsb_release['Release'] < 6.10:
            options = '''
options {
        directory "/var/cache/bind";
        auth-nxdomain no;    # conform to RFC1035
        listen-on-v6 { any; };
};
'''
            testlib.config_replace(self.options_file, options)

        # configure and restart bind9
        cfgfile = open('/etc/bind/db.autotest-zone.private', 'w')
        cfgfile.write('''
$TTL    604800
@       IN      SOA     private. root.localhost. (
                              1         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      localhost.
@       IN      A       172.20.0.1

mongoose    IN  A       172.20.0.10
serenity    IN  A       172.20.0.20
moya        IN  A       172.20.0.30

$GENERATE 100-200 guest-$   A  172.20.0.$
''')
        cfgfile.close()

        cfgfile = open('/var/cache/bind/db.autotest-zone.nsupdate', 'w')
        cfgfile.write('''
$TTL    604800
@       IN      SOA     nsupdate. root.localhost. (
                              1         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      localhost.
@       IN      A       172.30.0.1

foo     IN  A       172.30.0.10
bar     IN  A       172.30.0.20

$GENERATE 100-200 guest-$   A  172.30.0.$
''')
        cfgfile.close()

        cfgfile = open('/etc/bind/db.autotest-zone.public', 'w')
        cfgfile.write('''
$TTL    604800
@       IN      SOA     public. root.localhost. (
                              1         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      localhost.
@       IN      A       172.20.0.1

www    IN  A       172.20.0.10
smtp    IN  A       172.20.0.20
imap        IN  A       172.20.0.30

$GENERATE 100-200 vpn-$   A  172.20.0.$
''')
        cfgfile.close()

        cfgfile = open('/etc/bind/db.autotest-zone.172.20.0', 'w')
        cfgfile.write('''
$TTL    604800
@       IN      SOA     localhost. root.localhost. (
                              1         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      localhost.

; example network
0       IN      PTR     network.private.
10      IN      PTR     mongoose.private.
20      IN      PTR     serenity.private.
30      IN      PTR     moya.private.
$GENERATE 100-200 $ PTR guest-$.private.
255     IN      PTR     broadcast.private.
''')
        cfgfile.close()

        cfgfile = open('/var/cache/bind/db.autotest-zone.172.30.0', 'w')
        cfgfile.write('''
$TTL    604800
@       IN      SOA     localhost. root.localhost. (
                              1         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      localhost.

; example network
0       IN      PTR     network.nsupdate.
10      IN      PTR     foo.nsupdate.
20      IN      PTR     bar.nsupdate.
$GENERATE 100-200 $ PTR guest-$.nsupdate.
255     IN      PTR     broadcast.nsupdate.
''')
        cfgfile.close()

        cfgfile = open('/etc/bind/db.autotest-zone.10.20.0', 'w')
        cfgfile.write('''
$TTL    604800
@       IN      SOA     localhost. root.localhost. (
                              1         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      localhost.

; example network
0       IN      PTR     network.public.
10      IN      PTR     www.public.
20      IN      PTR     smtp.public.
30      IN      PTR     imap.public.
$GENERATE 100-200 $ PTR vpn-$.public.
255     IN      PTR     broadcast.public.
''')

        cfgfile.close()
        cfgfile = open('/etc/bind/autotest-conf.public', 'w')
        cfgfile.write('''
''')
        cfgfile.close()

        olddir = os.getcwd()
        os.chdir("/etc/bind")
        assert subprocess.call([
            'dnssec-keygen', '-r', '/dev/urandom', '-a', 'hmac-md5', '-b',
            '128', '-n', 'USER', 'dnsupdate'
        ],
                               stdout=subprocess.PIPE,
                               stderr=subprocess.STDOUT) == 0
        os.chdir(olddir)

        self.nsupdatekey = ""
        for name in os.listdir("/etc/bind"):
            if re.match(r'Kdnsupdate.*.key', name):
                keyfile = open(os.path.join("/etc/bind", name))
                for line in keyfile:
                    self.nsupdatekey = line.split()[6]
                    break
                keyfile.close()
                break

        cfgfile = open('/etc/bind/autotest-conf.private', 'w')
        cfgfile.write('''
zone "private" IN {
    type master;
    file "/etc/bind/db.autotest-zone.private";
    allow-transfer { 127.0.0.1; };
};

zone "0.20.172.in-addr.arpa" IN {
    type master;
    file "/etc/bind/db.autotest-zone.172.20.0";
    allow-transfer { 127.0.0.1; };
};
''')
        cfgfile.close()

        self.nsupdatefile = '/etc/bind/autotest.nsupdate'
        cfgfile = open(self.nsupdatefile, 'w')
        cfgfile.write('''server 127.0.0.1
key dnsupdate ''' + self.nsupdatekey + '''
zone 0.30.172.in-addr.arpa
update delete 50.0.30.172.in-addr.arpa
send
zone nsupdate
update delete dyndns.nsupdate.
send
zone 0.30.172.in-addr.arpa
update add 50.0.30.172.in-addr.arpa 600 IN PTR dyndns.nsupdate.
send
zone nsupdate
update add dyndns.nsupdate. 600 IN A 172.30.0.50
send
quit
''')
        cfgfile.close()

        cfgfile = open('/etc/bind/autotest-conf.nsupdate', 'w')
        cfgfile.write('''
key dnsupdate {
  algorithm hmac-md5;
  secret "''' + self.nsupdatekey + '''";
};
zone "nsupdate" IN {
    type master;
    file "/var/cache/bind/db.autotest-zone.nsupdate";
    allow-transfer { 127.0.0.1; };
    allow-update { key dnsupdate; };
};

zone "0.30.172.in-addr.arpa" IN {
    type master;
    file "/var/cache/bind/db.autotest-zone.172.30.0";
    allow-transfer { 127.0.0.1; };
    allow-update { key dnsupdate; };
};
''')
        cfgfile.close()

        if not os.path.exists('/etc/bind/named.conf.local.autotest'):
            shutil.copyfile('/etc/bind/named.conf.local',
                            '/etc/bind/named.conf.local.autotest')
        cfgfile = open('/etc/bind/named.conf.local', 'w')
        cfgfile.write('''
/*
view "local" {
    match-clients { localhost; };
*/

    include "/etc/bind/autotest-conf.public";
    include "/etc/bind/autotest-conf.private";
    include "/etc/bind/autotest-conf.nsupdate";
/*
};

view "public" {
    match-clients { any; };

    // notify our secondaries of any zone changes
    notify yes;
    allow-transfer { localhost; };

    include "/etc/bind/autotest-conf.public";
};
*/
''')
        cfgfile.close()

        self._set_initscript("/etc/init.d/bind9")
        self.daemon.stop()
        self.daemon.start()

        self.dns = adns.init(adns.iflags.noautosys, sys.stderr,
                             'nameserver 127.0.0.1')
예제 #34
0
######################################################################
if __name__ == "__main__":
    debug["*"] = 3

    nameservers = (
        (None, ),  # Default
        ("8.8.8.8", "8.8.4.4"),  # Google
        ("67.138.54.100", "207.225.209.66"),  # ScrubIt
        ("156.154.70.1", "156.154.71.1"),  # dnsadvantage
        ("208.67.222.222", "208.67.220.220"),  # OpenDNS
        ("199.166.28.10", "199.166.29.3", "199.166.31.3", "204.57.55.100",
         "199.5.157.128"))  # ORSC

    ns = nameservers[0][0]
    if ns == None:
        res = adns.init(adns.iflags.noautosys)
    else:
        res = adns.init(adns.iflags.noautosys, sys.stderr,
                        "nameserver %s" % ns)

    x = IPResolver(res=res)
    x.submit(sys.argv[1:])
    x.wait()
    ip2i = x.query()

    for ip in sys.argv[1:]:
        i = ip2i[ip]
        print "%-40s %-10s %-6s %-25s %-14s %s %s %s" % \
          ("ip=%s [%s]" % (i.ip, i.cidr),
           "asn=%s,%s" % (i.asn.cc, i.asn.asn),
           "cc=%s" % i.geoip.cc,
예제 #35
0
	def run(self):
		testId = self.getInput('testId')
		records = self.getInput('MXRecord')
		pluginName = self.__class__.__name__
		ipregexp = compile(r'^([0-9]*).([0-9]*).([0-9]*).([0-9]*)$')

		res = adns.init()

		blacklist = []
		blacklist.append(("multi.uribl.com", "http://uribl.com"))
		blacklist.append(("dsn.rfc-ignorant.org", "http://rfc-ignorant.org"))
		blacklist.append(("dul.dnsbl.sorbs.net", "http://www.au.sorbs.net"))
		blacklist.append(("sbl-xbl.spamhaus.org", "http://spamhaus.org"))
		blacklist.append(("bl.spamcop.net", "http://spamcop.net"))
		blacklist.append(("dnsbl.sorbs.net", "http://www.au.sorbs.net"))
		blacklist.append(("cbl.abuseat.org", "http://abuseat.org"))
		blacklist.append(("ix.dnsbl.manitu.net", "http://www.dnsbl.manitu.net"))
		blacklist.append(("combined.rbl.msrbl.net", "http://msrbl.net"))
		blacklist.append(("rabl.nuclearelephant.com", "http://nuclearelephant.com"))

		self.result.info('Starting Blacklist-test')

		if len(records['mx_record']) <= 0:
			result.error('Test could not be executed')

		results = []
		statusCounts = {Plugin.STATUS_OK: 0, Plugin.STATUS_WARNING: 0, Plugin.STATUS_ERROR: 0}

		for record in records['mx_record']:
			host = record['host']
			ip = record['ip']
			blacklistip = sub(ipregexp, r'\4.\3.\2.\1', ip)

			code = Plugin.STATUS_OK
			reply_code = reply_msg = None
			try:
				for cbl in blacklist:
					url = cbl[1]
					cbl = cbl[0]

					cblhost = str(blacklistip + "." + cbl)
					self.livefeedback.message(testId, "%s, subtest: %s in %s?", (pluginName, ip, cbl))
					try:
						addr = res.synchronous(cblhost, adns.rr.A)
						reply_code = addr[3][0]
						msg = res.synchronous(cblhost, adns.rr.TXT)
						reply_msg = msg[3][0][0]
					except:
						pass

					# Add status message
					if(match(ipregexp, str(reply_code))):
						self.result.warning('%s (%s) is listed on blacklist %s, result: %s, text: %s.', (ip, host, cbl, reply_code, reply_msg))
						self.result.extra('<a href="%s" target="_blank">%s</a>' % (url, url), type='all')
					else:
						self.result.info('%s (%s) is not listed on blacklist %s.', (ip, host, cbl))
						self.result.extra('<a href="%s" target="_blank">%s</a>' % (url, url), type='adv')

					results.append([host, ip, cblhost, reply_code, reply_msg])
					statusCounts[code] += 1
			except:
				pass

		# Figure the final status of the test
		code = Plugin.STATUS_OK
		if statusCounts[Plugin.STATUS_WARNING] > 0 and statusCounts[Plugin.STATUS_WARNING] == len(results):
			code = Plugin.STATUS_ERROR
			self.result.error('All Blacklist-tests failed!')

		self.result.extra('more info blacklists', type='adv')
		self.result.info('Finished Blacklist-test')
		self.result.setTestStatus(code)
예제 #36
0
 def __init__(self,s=None):
     self._s=s or adns.init(adns.iflags.noautosys)
     self._queries={}
     self.IPhost={}
예제 #37
0
    def __init__(self,
                 cachedir=None,
                 gip=None,
                 psl=None,
                 res=None,
                 maxtime=30,
                 maxtries=3):
        """Constructor.

    Initialises the lookup object so it is ready for queries.

    @param cachedir -- Default location for caching databases, used if
    `gip` or `psl` have not been specified. If unset and neither `gip`
    nor `psl` arguments are provided, the databases are cached in the
    current directory.

    @param gip -- Reference to GeoIPLookup object. If None, a new
    object is created, using `cachedir` or current directory as the
    location for the city database file.

    @param psl -- Reference to PublicSuffixLookup object. If None, a
    new object is created, using `cachedir` or current directory as
    the location for the YAML cache database.

    @param res -- Reference to adns DNS resolver object. If None, a
    new resolver is created. If you want to use a nameserver other
    than your system default one, pass in custom adns object created
    with the appropriate "nameserver x.y.z.w" resolver argument.

    @param maxtime -- The maximum time to wait for DNS replies. Some
    DNS servers are slow to respond so some queries take a long time
    to complete, or will simply time out. If the client is submitting
    large numbers of addresses for query, the stragglers are handled
    automatically and there is no reason to reduce the query time-out.
    However if the client has just a few addresses to resolve, or is
    in a hurry to get the answer, set `maxtime` to some smaller value.

    @param maxtries -- The maximum number of times to attempt main
    queries per IP address. In general this value should be greater
    than one to avoid failures resulting from dropped DNS packets and
    to catch straggler responses from slow, far away and somewhat
    misconfigured DNS servers. More than three rarely improves the
    accuracy of the results.
    """
        now = time()
        self.maxtime = maxtime
        self.maxtries = maxtries
        geopath = (cachedir and "%s/GeoLiteCity.dat" % cachedir)
        pslpath = (cachedir and "%s/psl.yml" % cachedir)
        self.res = res or adns.init(adns.iflags.noautosys)
        debug("IP2INFO", 2, "dns resolver initialised %.2f", time() - now)
        self.gip = gip or GeoIPLookup(path=geopath)
        debug("IP2INFO", 2, "geoip resolver initialised %.2f", time() - now)
        self.psl = psl or PublicSuffixLookup(path=pslpath)
        debug("IP2INFO", 2, "domain resolver initialised %.2f", time() - now)
        self.ptrfail = set()
        self.ptrmap = {}
        self.asnmap = {}
        self.queries = {}
        self.ipaddrs = {}
        self.resstat = {}
        for cidr in self.UNAVAILABLE.iter_cidrs():
            asn = "@%s" % str(cidr)
            self.asnmap[asn] = ASInfo(asn=asn, cc="--")
        debug("IP2INFO", 1, "initialisation complete %.2f", time() - now)
예제 #38
0
    def run(self):
        domain = self.getInput('domain')

        self.result.info('Starting MX record lookup against %s', (domain))
        dns = adns.init()
        mxRecords = dns.synchronous(domain, adns.rr.MX)
        records = []
        if (len(mxRecords[3]) >= 1):

            for i in mxRecords[3]:
                prio = str(i[0])
                host = i[1][0]
                ipv = get_ipv_type(host)
                if len(ipv) <= 2:
                    if self.logger:
                        self.logger.debug(
                            "Failed to find IPv type for host \"%s\"" % host)
                    continue
                if self.logger:
                    self.logger.debug("Host: %s, Prio: %s, IPv: %s" %
                                      (host, prio, ipv))

                records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
                  'connection_type': ipv[1]})
                self.result.info('Found host %s (%s), priority %s',
                                 (host, ipv[2], prio))
                if (ipv[1] == "INET6"):
                    ipv = get_ipv_type(host, "INET")
                    if (ipv[2] != None):
                        records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
                         'connection_type': ipv[1]})
                        self.result.info('Found host %s (%s), priority %s',
                                         (host, ipv[2], prio))
        else:
            prio = "-1"
            host = domain
            ipv = get_ipv_type(host)
            if len(ipv) != 0:
                records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
                 'connection_type': ipv[1]})
                self.result.info('Found host %s (%s), priority %s',
                                 (host, ipv[2], prio))
                if (ipv[1] == "INET6"):
                    ipv = get_ipv_type(host, "INET")
                    if (ipv[2] != None):
                        records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
                         'connection_type': ipv[1]})
                        self.result.info('Found no MX-record, using host %s (%s)', \
                          (host, ipv[2]))

        message = ""
        code = Plugin.STATUS_OK
        if len(records) == 0:
            message = 'No records found'
            code = Plugin.STATUS_ERROR
            self.result.error(message)
        elif len(records
                 ) == 1 and records[0]['prio'] == "-1" and self.isChild != 0:
            message = 'No MX-records found, using A/AAAA-record'
            code = Plugin.STATUS_OK
            self.result.info(message)
        elif len(records
                 ) == 1 and records[0]['prio'] == "-1" and self.isChild == 0:
            message = 'No MX-records found, using A/AAAA-record'
            code = Plugin.STATUS_WARNING
            self.result.warning(message)
        elif len(records) == 1 and records[0]['connection_type'] == "INET6" \
          and self.isChild == 0:
            message = 'Only IPv6 addresses found, this might cause delivery problems'
            code = Plugin.STATUS_WARNING
            self.result.warning(message)
        elif len(records) == 1 and self.isChild == 0:
            message = 'Only one record found, two or more is recommended'
            code = Plugin.STATUS_OK
            self.result.info(message)
        else:
            message = 'Multiple MX-records found'
            code = Plugin.STATUS_OK
            self.result.info(message)

        self.result.extra('more info mx record', type='adv')

        self.result.info('Finished MX record lookup against %s', (domain))

        # Output
        if len(records) == 0:
            self.result.setOutput(None)
        else:
            self.result.setOutput({'mx_record': records}, persist=True)

        self.result.setTestStatus(code)
예제 #39
0
#!/bin/env/python

import csv
import adns
import os.path
c = adns.init()

#Check if results file exists already.
if os.path.isfile('plzworkresults.csv'):
    print "A results file already exists!"
# If no results file, resolve all of the domains in top-1m.csv
else:
    reader = csv.reader(open('top-1m.csv', 'r'))
    alexadict = {}
    for row in reader:
        k, v = row
        alexadict[k] = v
    writer = csv.writer(open('plzworkresults.csv', 'wb'))
    resolvdict = {}
    count = 0
    for key, value in alexadict.iteritems():
        try:
            resolved = c.synchronous(value, adns.rr.A)
            resolvdict.setdefault(key, [value]).append(resolved[3])
            for key, value in resolvdict.iteritems():
                writer.writerow([key, value])
            resolvdict = {}
            count += 1
            print "We've resolved %d domains." % count
        except IOError:
            pass
예제 #40
0
if len(sys.argv) == 2:
	host_file = sys.argv[1]
else:
	print "Usage:",sys.argv[0],"[Hosts_File]"
	exit()

with open(host_file, 'r') as f:
	hosts = [line.strip() for line in f]

intensity = 50
resolved_hosts = {}
active_queries = {}
host_queue = hosts[:]
success = 0
mainsub = adns.init()

def collect_results():
	global success
	for query in mainsub.completed():
		answer = query.check()
		host = active_queries[query]
		del active_queries[query]
		if answer[0] == 0:
			ip = answer[3][0]
			success += 1
			resolved_hosts[host] = ip
		elif answer[0] == 101: # CNAME
			query = mainsub.submit(answer[1], adns.rr.A)
			active_queries[query] = host
		else:
예제 #41
0
 def __init__(self):
     self.adns = adns.init()
예제 #42
0
class config:
	verbose = False
	maxcons = 1000

#### State ####

dns_cache = {}		# {host : ip}
adns_queries = {}	# {query : context}
connections = {}	# {fileno : context}
statistics = {}		# {Error : count}
epoll = select.epoll()
queue = Queue()
timers = []
global current
current = None
resolver = adns.init(adns.iflags.noautosys)

#### Exeptions ####

class ConnectionError(Exception):
	pass

class TimeoutError(ConnectionError):
	pass

class ConnectError(ConnectionError):
	pass

class DomainError(ConnectionError):
	pass
예제 #43
0
# Print a message every X number of queries
printCount = 100
 
 
import adns
import sys
import time
 
totalStart = time.time()
urlFile = open("sites.txt", "r")
urlList = urlFile.readlines()
 
run = 0
while run < runs:
    for server in servers:
        s = adns.init(adns.iflags.noautosys,sys.stderr, "nameserver " + server)
        if run == 0:
            resultsDataFile = open("DNS-Results-" + server + ".csv", "w")
        else:
            resultsDataFile = open("DNS-Results-" + server + ".csv", "a")
        count = 0
        quickestTime = 999999.9
        longestTime = 1.0
        averageTime = 999999.9
        totalTimeMS = 999999.9
        print "Server: " + server + ""
        print "Run: " + str(run + 1) + ""
        while count < queries:
            timeStart = time.time()
            resolve = s.synchronous(urlList[count].strip(), adns.rr.A)
            # For asynchronis queries use below line
예제 #44
0
 def __init__(self, ip):
     ADNS.QueryEngine.__init__(self, s=adns.init(
             adns.iflags.noautosys, sys.stderr, 'nameserver %s' % ip))
     self.ip = ip
     self.queries = []
     self.results = {}
예제 #45
0
#!/bin/env/python

import csv
import adns
import os.path
c=adns.init()

#Check if results file exists already.
if os.path.isfile('plzworkresults.csv'):
	print "A results file already exists!"
# If no results file, resolve all of the domains in top-1m.csv
else:
	reader = csv.reader(open('top-1m.csv', 'r'))
	alexadict = {}
	for row in reader:
		k, v = row
		alexadict[k] = v
	writer = csv.writer(open('plzworkresults.csv', 'wb')) 
	resolvdict = {}
	count = 0
	for key, value in alexadict.iteritems():
	    try:
	        resolved = c.synchronous(value, adns.rr.A)
	        resolvdict.setdefault(key, [value]).append(resolved[3])
	        for key, value in resolvdict.iteritems():
				writer.writerow([key, value])
		resolvdict = {}
	        count += 1
	        print "We've resolved %d domains." % count
	    except IOError:
	        pass
예제 #46
0
    def run(self):
        """
		Called by the test runner script to start execution of the test.
		"""
        # Get the domain we are testing so we can lookup MX records
        domain = self.getInput('domain')

        # Log a default info message which will turn up under advanced in the frontend. The string is a uid which
        # will be translated and each %s will be replaced with the values from second argument that should be a tuple.
        self.result.info('Starting MX record lookup against %s', (domain))

        # Initialize the adns module
        dns = adns.init()

        # lookup MX records for the domain
        mxRecords = dns.synchronous(domain, adns.rr.MX)

        # Create a list for the MX records
        records = []
        if (len(mxRecords[3]) >= 1):

            # if any MX-record was found, loop through each record
            for i in mxRecords[3]:
                prio = str(i[0])
                host = i[1][0]
                ipv = get_ipv_type(host)
                if self.logger:
                    self.log.info("Host: %s, Prio: %s, IPv: %s" %
                                  (host, prio, ipv))

                # Add the found records to the list with records. We save priority, host, IP and IP version (INET or INET6)
                records.append({
                    'prio': prio,
                    'host': ipv[0],
                    'ip': ipv[2],
                    'connection_type': ipv[1]
                })

                # Add a line to the frontend informing the user about the record we found
                self.result.info('Found host %s (%s), priority %s',
                                 (host, ipv[2], prio))

                # if record type is IPv6 also obtain IPv4 address if possible
                if (ipv[1] == "INET6"):
                    ipv = get_ipv_type(host, "INET")
                    if (ipv[2] != None):
                        records.append({
                            'prio': prio,
                            'host': ipv[0],
                            'ip': ipv[2],
                            'connection_type': ipv[1]
                        })
                        self.result.info('Found host %s (%s), priority %s',
                                         (host, ipv[2], prio))
        else:
            # If no MX record was found, we try to use the A record instead
            # Set prio to -1 to symbolise that no MX-record is available and only hostname is used
            prio = "-1"
            host = domain

            ip = get_arecord(domain)
            ipv = get_ipv_type(host)

            # If a A record is set use that one for further tests instead of MXRecord
            if len(ipv) != 0:
                records.append({
                    'prio': prio,
                    'host': ipv[0],
                    'ip': ipv[2],
                    'connection_type': ipv[1]
                })
                self.result.info('Found host %s (%s), priority %s',
                                 (host, ipv[2], prio))
                # If the hostname has a AAAA-record also check if a A-record exists
                if (ipv[1] == "INET6"):
                    ipv = get_ipv_type(host, "INET")
                    if (ipv[2] != None):
                        records.append({
                            'prio': prio,
                            'host': ipv[0],
                            'ip': ipv[2],
                            'connection_type': ipv[1]
                        })
                        self.result.info(
                            'Found no MX-record, using host %s (%s)',
                            (host, ipv[2]))

        # Set final status code and message
        message = ""
        code = Plugin.STATUS_OK
        if len(records) == 0:
            message = 'No records found'
            code = Plugin.STATUS_ERROR
            self.result.error(message)
        elif len(records
                 ) == 1 and records[0]['prio'] == "-1" and self.isChild != 0:
            message = 'No MX-records found, using A/AAAA-record'
            code = Plugin.STATUS_OK
            self.result.info(message)
        elif len(records
                 ) == 1 and records[0]['prio'] == "-1" and self.isChild == 0:
            message = 'No MX-records found, using A/AAAA-record'
            code = Plugin.STATUS_WARNING
            self.result.warning(message)
        elif len(records) == 1 and records[0][
                'connection_type'] == "INET6" and self.isChild == 0:
            message = 'Only IPv6 addresses found, this might cause delivery problems'
            code = Plugin.STATUS_WARNING
            self.result.warning(message)
        elif len(records) == 1 and self.isChild == 0:
            message = 'Only one record found, two or more is recommended'
            code = Plugin.STATUS_OK
            self.result.info(message)
        else:
            message = 'Multiple MX-records found'
            code = Plugin.STATUS_OK
            self.result.info(message)

        # Print final message to advanced output
        self.result.info('Finished MX record lookup against %s', (domain))

        if len(records) == 0:
            # If we didn't find any records at all, output from this plugin should be None
            self.result.setOutput(None)
        else:
            # Create the final output dict and mark it with the persist flag. That will
            # cause the result to be automatically saved to the database.
            self.result.setOutput({'mx_record': records}, persist=True)

        # Set the final test status for this plugin (shown in UI)
        self.result.setTestStatus(code)
예제 #47
0
    def run(self):
        pluginName = self.__class__.__name__
        testId = self.getInput("testId")
        email = self.getInput("email")
        mx = self.getInput("MXRecord")
        dns = adns.init()

        records = []
        raw = []
        resolves = []
        highestPrio = 0

        port = 25

        self.result.info("Started open relay test")

        failedTests = {}
        myhostname = socket.getfqdn()

        relayTestsCount = 0
        testnr = 1
        nrMXRecords = len(mx[1])
        for row in mx[1]:
            host = row[1]
            ip = row[2]
            type = row[3]

            failedTests[host] = []
            try:
                s = connect_to_host(host, port, type)
                data = s.recv(1024)
            except Exception, e:
                self.result.warning("Failed to connect to %s (%s)", (host, ip))
                continue

            self.result.info("Starting open relay tests against %s", host)

            mailfrom = []
            mailrcpt = []

            mailfrom.append("<spamtest@" + myhostname + ">")
            mailrcpt.append("<relaytest@" + myhostname + ">")
            mailfrom.append("<spamtest@" + myhostname + ">")
            mailrcpt.append("relaytest@" + myhostname + "")
            mailfrom.append("<spamtest>")
            mailrcpt.append("<relaytest@" + myhostname + ">")
            mailfrom.append("<>")
            mailrcpt.append("<relaytest@" + myhostname + ">")
            mailfrom.append("<spamtest@" + host + ">")
            mailrcpt.append("<relaytest@" + myhostname + ">")
            mailfrom.append("<spamtest@[" + ip + "]>")
            mailrcpt.append("<relaytest@" + myhostname + ">")
            mailfrom.append("<spamtest@" + host + ">")
            mailrcpt.append("<relaytest%" + myhostname + "@" + host + ">")
            mailfrom.append("<spamtest@" + host + ">")
            mailrcpt.append("<relaytest%" + myhostname + "@[" + ip + "]>")
            mailfrom.append("<spamtest@" + host + ">")
            mailrcpt.append('<"relaytest@' + myhostname + '">')
            mailfrom.append("<spamtest@" + host + ">")
            mailrcpt.append('<"relaytest%' + myhostname + '">')
            mailfrom.append("<spamtest@" + host + ">")
            mailrcpt.append("<relaytest@" + myhostname + "@" + host + ">")
            mailfrom.append("<spamtest@" + host + ">")
            mailrcpt.append('<"relaytest@' + myhostname + '"@' + host + ">")
            mailfrom.append("<spamtest@" + host + ">")
            mailrcpt.append("<relaytest@" + myhostname + "@[" + ip + "]>")
            mailfrom.append("<spamtest@" + host + ">")
            mailrcpt.append("<@" + host + ":relaytest@" + myhostname + ">")
            mailfrom.append("<spamtest@" + host + ">")
            mailrcpt.append("<@[" + ip + "]:relaytest@" + myhostname + ">")
            mailfrom.append("<spamtest@" + host + ">")
            mailrcpt.append("<" + myhostname + "!relaytest>")
            mailfrom.append("<spamtest@" + host + ">")
            mailrcpt.append("<" + myhostname + "!relaytest@" + host + ">")
            mailfrom.append("<spamtest@" + host + ">")
            mailrcpt.append("<" + myhostname + "!relaytest@[" + ip + "]>")
            mailfrom.append("<spamtest@" + host + ">")
            mailrcpt.append("<relaytest%[" + myhostname + "]@>")
            mailfrom.append("<spamtest@" + host + ">")
            mailrcpt.append("<relaytest@[" + myhostname + "]@>")
            relayTestsCount = len(mailfrom)

            try:
                result
            except:
                result = []

            for testno in range(len(mailfrom)):
                self.livefeedback.message(
                    testId,
                    "%s, running subtest %s of %s on server %s (%s/%s)",
                    (pluginName, (testno + 1), len(mailfrom), host, testnr, nrMXRecords),
                )
                test = [
                    [
                        "HELO " + host + "\r\n",
                        "RSET\r\n",
                        "MAIL FROM: " + mailfrom[testno] + "\r\n",
                        "RCPT TO: " + mailrcpt[testno] + "\r\n",
                    ],
                    ["250", "250 2.0.0 Ok|250 2.1.5 Flushed.*", "250 2.1.0 Ok", "250 2.1.0 Ok"],
                    ["554.*|501.*|503.*|553.*|550.*|555.*|401.*|454.*"],
                ]

                testlog = ""

                for row in range(len(test[1])):
                    exit_code = int()
                    send = test[0][row]
                    recv = test[1][row]

                    try:
                        s.send(send)
                    except Exception, e:
                        if e[0] == 104:
                            self.result.info("Warning connection reset by peer..")
                        if e[0] == 32:
                            self.result.info("Warning broken pipe, aborting subtest..")
                            s = connect_to_host(host, port, type)
                            # continue
                    testlog += ">>> " + send

                    try:
                        data = s.recv(1024)
                    except Exception, e:
                        if e[0] == 104:
                            self.result.info("Warning connection reset by peer..")
                        if e[0] == 32:
                            # self.result.info("Warning broken pipe, aborting subtest..")
                            s = connect_to_host(host, port, type)
                            # continue

                    testlog += "<<< " + data

                    if not match(recv, data):
                        if not match(test[2][0], data):
                            exit_code = 1
                    elif row == (len(test[0]) - 1):
                        exit_code = 0

                    if exit_code == 0 and row == (len(test[0]) - 1):
                        self.result.info("Test %s on host %s:\n%s", ((testno + 1), host, testlog))
                    elif exit_code == 1 and row == (len(test[0]) - 1):
                        self.result.warning("Test %s FAILED on %s:\n%s", ((testno + 1), host, testlog), "adv")
                        failedTests[host].append(testno + 1)
                        failed = 1
예제 #48
0
파일: MXRecord.py 프로젝트: dotse/Mailcheck
	def run(self):
		"""
		Called by the test runner script to start execution of the test.
		"""
		# Get the domain we are testing so we can lookup MX records
		domain = self.getInput('domain')

		# Log a default info message which will turn up under advanced in the frontend. The string is a uid which
		# will be translated and each %s will be replaced with the values from second argument that should be a tuple.
		self.result.info('Starting MX record lookup against %s', (domain))

		# Initialize the adns module
		dns = adns.init()

		# lookup MX records for the domain
		mxRecords = dns.synchronous(domain, adns.rr.MX)

		# Create a list for the MX records
		records = []
		if (len(mxRecords[3]) >= 1):
		
			# if any MX-record was found, loop through each record
			for i in mxRecords[3]:
				prio = str(i[0])
				host = i[1][0]
				ipv = get_ipv_type(host)
				if self.logger:
					self.log.info("Host: %s, Prio: %s, IPv: %s" % (host, prio, ipv))

				# Add the found records to the list with records. We save priority, host, IP and IP version (INET or INET6)
				records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], 'connection_type': ipv[1]})

				# Add a line to the frontend informing the user about the record we found
				self.result.info('Found host %s (%s), priority %s', (host, ipv[2], prio) )

				# if record type is IPv6 also obtain IPv4 address if possible
				if (ipv[1] == "INET6"):
					ipv = get_ipv_type(host, "INET")
					if (ipv[2] != None):
						records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], 'connection_type': ipv[1]})
						self.result.info('Found host %s (%s), priority %s', (host, ipv[2], prio) )
		else:
			# If no MX record was found, we try to use the A record instead
			# Set prio to -1 to symbolise that no MX-record is available and only hostname is used
			prio="-1"
			host=domain

			ip=get_arecord(domain)
			ipv=get_ipv_type(host)

			# If a A record is set use that one for further tests instead of MXRecord
			if len(ipv) != 0:
				records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], 'connection_type': ipv[1]})
				self.result.info('Found host %s (%s), priority %s', (host, ipv[2], prio) )
				# If the hostname has a AAAA-record also check if a A-record exists
				if (ipv[1] == "INET6"):
					ipv = get_ipv_type(host, "INET")
					if (ipv[2] != None):
						records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], 'connection_type': ipv[1]})
						self.result.info('Found no MX-record, using host %s (%s)', (host, ipv[2]) )

		# Set final status code and message
		message = ""
		code = Plugin.STATUS_OK
		if len(records) == 0: 
			message = 'No records found'
			code = Plugin.STATUS_ERROR
			self.result.error(message)
		elif len(records) == 1 and records[0]['prio'] == "-1" and self.isChild != 0:
			message = 'No MX-records found, using A/AAAA-record'
			code = Plugin.STATUS_OK
			self.result.info(message)
		elif len(records) == 1 and records[0]['prio'] == "-1" and self.isChild == 0:
			message = 'No MX-records found, using A/AAAA-record'
			code = Plugin.STATUS_WARNING
			self.result.warning(message)
		elif len(records) == 1 and records[0]['connection_type'] == "INET6" and self.isChild == 0:
			message = 'Only IPv6 addresses found, this might cause delivery problems'
			code = Plugin.STATUS_WARNING
			self.result.warning(message)
		elif len(records) == 1 and self.isChild == 0:
			message = 'Only one record found, two or more is recommended'
			code = Plugin.STATUS_OK
			self.result.info(message)
		else:
			message = 'Multiple MX-records found'
			code = Plugin.STATUS_OK
			self.result.info(message)

		# Print final message to advanced output
		self.result.info('Finished MX record lookup against %s', (domain))

		if len(records) == 0:
			# If we didn't find any records at all, output from this plugin should be None
			self.result.setOutput(None)
		else:
			# Create the final output dict and mark it with the persist flag. That will
			# cause the result to be automatically saved to the database.
			self.result.setOutput({'mx_record': records}, persist=True)
	
		# Set the final test status for this plugin (shown in UI)
		self.result.setTestStatus(code)