本文整理汇总了Python中DatabaseHandler.DatabaseHandler.getClientIPs方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseHandler.getClientIPs方法的具体用法?Python DatabaseHandler.getClientIPs怎么用?Python DatabaseHandler.getClientIPs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseHandler.DatabaseHandler
的用法示例。
在下文中一共展示了DatabaseHandler.getClientIPs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import getClientIPs [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()