当前位置: 首页>>代码示例>>Python>>正文


Python Mapper.searchType方法代码示例

本文整理汇总了Python中mapper.Mapper.searchType方法的典型用法代码示例。如果您正苦于以下问题:Python Mapper.searchType方法的具体用法?Python Mapper.searchType怎么用?Python Mapper.searchType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mapper.Mapper的用法示例。


在下文中一共展示了Mapper.searchType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from mapper import Mapper [as 别名]
# 或者: from mapper.Mapper import searchType [as 别名]
class DNSClassifier:
    def __init__(self):
        #may want to enhance this with a pre-load file to prepopulate the DB
        self.db = {}                   # dictionary of DNSClassifierEntrys
        self.mapper = Mapper()
        self.new_callbacks = []        # For each new entry
        self.update_callbacks = []     # For each time an entry is updated
        self.all_callbacks = []        # When entry is updated or new
        self.class_callbacks = {}      # Dictionary of lists of callbacks per
                                       # classification

    def parse_new_DNS(self, packet):
        # Only look at responses with 'No error' reply code
        dns_parsed = dns.parser(packet)
        if (dns_parsed.qr and dns_parsed.rcode == 0000):
            # skip the questions...
            # we don't care about authorities
            # we care about answers
            # we care about additional - could be some goodies in there
            for resp in (dns_parsed.answers + dns_parsed.additional):
                # save off the ttl, classification, calculate expiry time
                # Name of item that's being saved, 
                if (resp.qtype == dns.rr.A_TYPE):
                    classification = self.mapper.searchType(resp.name)
                    addr = addrconv.ipv4.bin_to_text(resp.rddata)
                    
                    if addr not in self.db.keys():
                        self.db[addr] =  Entry(addr, list(), classification,
                                               resp.ttl)
                        self.db[addr].names.append(resp.name)
                        for callback in self.new_callbacks:
                            callback(addr, self.db[addr])
                        if classification in self.class_callbacks.keys():
                            for callback in self.class_callbacks[classification]:
                                callback(addr, self.db[addr])
                    else:
                        self.db[addr].update_expiry(resp.ttl)
                        old_class = self.db[addr].classification
                        self.db[addr].classification = classification

                        if resp.name not in self.db[addr].names:
                            self.db[addr].names.append(resp.name)
                        for callback in self.update_callbacks:
                            callback(addr, self.db[addr])
                        if old_class != classification:
                            if classification in self.class_callbacks.keys():
                                for callback in self.class_callbacks[classification]:
                                    callback(addr, self.db[addr])

                    for callback in self.all_callbacks:
                        callback(addr, self.db[addr])

                elif (resp.qtype == dns.rr.AAAA_TYPE):
                    #placeholder
                    print "Found a AAAA"
                elif (resp.qtype == dns.rr.CNAME_TYPE):
                    #placeholder
                    print "Found a CNAME!"
                elif (resp.qtype == dns.rr.MX_TYPE):
                    #placeholder
                    print "Found an MX!"

    def _install_new_rule(self, domain, addr):
        # DIRTY, doesn't handle classification.
        if addr not in self.db.keys():
            self.db[addr] = Entry(addr, list(), "", 1000)
            self.db[addr].names.append(domain)
            for callback in self.new_callbacks:
                callback(addr, self.db[addr])

        else:
            self.db[addr].update_expiry(1000)
            
            if domain not in self.db[addr].names:
                self.db[addr].names.append(domain)
            for callback in self.update_callbacks:
                callback(addr, self.db[addr])
            

    def _clean_expiry_full(self):
        # Loop through everything to check for expired DNS entries
        for key in self.db.keys():
            entry = self.db[key]
            if entry.is_expired():
                del self.db[key]

    def clean_expired(self):
        self._clean_expiry_full()
        
    def print_entries(self):
        for key in self.db.keys():
            self.db[key].print_entry()

    def set_new_callback(self, cb):
        if cb not in self.new_callbacks:
            self.new_callbacks.append(cb)

    def remove_new_callback(self, cb):
        self.new_callbacks.remove(cb)

#.........这里部分代码省略.........
开发者ID:sdonovan1985,项目名称:netassay,代码行数:103,代码来源:dnsclassify.py


注:本文中的mapper.Mapper.searchType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。