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


Python DatabaseHandler.getModulePortsAndNames方法代码示例

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


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

示例1: __init__

# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import getModulePortsAndNames [as 别名]
class ManualSanityCheckerService:
    
    def __init__(self, host, port, db):
        """
        Initialises the service.
        @type host: string
        @param host: the IP to listen on.
        @type port: integer
        @param port: the port to listen on.
        @type db: string
        @param db: path to the SQLite database file.
        """
        self.db = DatabaseHandler(db)
        self.host = host
        self.port = port
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
        self.sock.bind((host,port))
        self.sock.listen(1)
        self.modules = self.db.getModulePortsAndNames()

    def startServer(self):
        self.running = True
        while self.running:
            conn, addr = self.sock.accept()
            self.handle(conn, addr)
            conn.close()
        self.sock.close()

    def handle(self, conn, addr):
        """Handles a request"""
        data = conn.recv(1024).strip('\n')
        if data.startswith("CHECK TYPE "):
            self.contestants = self.db.getClientIPs()
            checktype = data.split(' ')[2]
            IP = data.split(' ')[3]
            if checktype == "NORMAL":
                logging.info("[MANUALNORMAL] Starting check")
                for module in self.modules:
                    logging.info("Checking module " + module['name'] + "on port " + str(module['port']))
                    result = checkIP(IP, module['port'])[0]
                    if not result['fine']:
                        logging.info("[MANUALNORMAL] Adding " + IP + " with port " + str(result['port']))
                        self.db.addSuspiciousContestant(IP, result['port'],'',module['name'])
                logging.info("[MANUALNORMAL] Finished check")

            elif checktype == "P2P":
                logging.info("[MANUALP2P] Starting check")
                for module in self.modules:
                    logging.info("[MANUALP2P] Checking module " + module['name'] + " on port " + str(module['port']))
                    self.targets = copy.copy(self.contestants)
                    self.targets.remove(IP)
                    p2p = P2PSanityCheck.PeerToPeerSanityChecker(IP,self.targets, module['port'])
                    p2p.checkIP()
                    results = p2p.getResults()
                    for client in results:
                        for result in client['results']:
                            #logging.info("%s reports port %s on %s: fine = %s" % (client['IP'], result['port'], IP, result['fine']))
                            if result['fine'] == 'False':
                                if  result['port'] == "":
                                    logging.info("[MANUALP2P] Adding " + client['IP'] + " for not running P2PRequestListener")
                                    self.db.addSuspiciousContestant(client["IP"], "","", "PeerToPeerRequestListener")
                                else:
                                    logging.info("[MANUALP2P] Adding " + IP + " with port " + str(result['port']) + "reported by " + client['IP'])
                                    self.db.addSuspiciousContestant(IP, result['port'], client['IP'], module['name'])
                logging.info("[MANUALP2P] Finished check.")

        elif data == "STOPMANUAL":
            logging.info("[MANUALSERVICE] Stopping Manual Sanity Check Service...")
            self.running = False
        
    def stopServer(self):
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect((self.host, self.port))
        sock.send('STOPMANUAL')
        sock.close()
开发者ID:Hazelwire,项目名称:Hazelwire,代码行数:78,代码来源:ManualSanityChecker.py


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