受控节点slave.py
复制代码 代码如下:
import socket
import re
class Log(object):
file_list=['access.log','C:\\access.log']
master_ip='192.168.0.103'
def init(self):
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(('',3333))
s.listen(1)
while True:
conn,addr=s.accept()
print addr[0]
if addr[0]==self.master_ip:
reg=conn.recv(1024)
result=self.all_log(reg)
conn.sendall(result)
conn.close()
def all_log(self,reg):
logs=''
for f in self.file_list:
logs+='\n'+self.log_match(f,reg)
return logs
def log_match(self,f,reg):
log_result='------------------------'+f+'------------------------'+'\n'
fo=open(f,'r')
line=fo.readline()
rp=re.compile(reg)
while line!='':
log_match=rp.match(line)
if log_match:
log_result+='\n'+log_match.group()
line=fo.readline()
return log_result
if name=='main':
ds=Log()
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8