Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import commands,re,time
- import subprocess
- TCPDUMP = "tcpdump "
- operation='ps | grep tcpdump'
- PATTERN = "\d+(?=\s)"
- DUMP_TIME = 300
- PATTERN_TIME = "[0-9]{2}:[0-9]{2}:[0-9]"
- PORTS = ["8080", "8070", "8060"]
- PATH = "/home/nirs/dump/service_"
- query_dir = "mkdir -p /home/nirs/dump/service_"
- def get_time():
- timest = re.findall(PATTERN_TIME,time.ctime())[0]
- return timest
- def dir_maker():
- commands.getoutput("-u root mkdir /nirs/koibasta")
- for port in PORTS:
- result = commands.getoutput(query_dir+port)
- def start_dump():
- for port in PORTS:
- new_cmd = TCPDUMP+" -s 0 -w \""+PATH+port+"/date+%F--%H-%M.dump\" -G " + str(DUMP_TIME) + " -i eth0 'port "+port+"' &"
- print new_cmd
- result = subprocess.call(new_cmd,shell=True)
- def kill_proc():
- result = commands.getoutput(operation)
- ar = result.split("\n")
- PID = []
- for x in ar:
- print(x)
- match = re.search(PATTERN,x)
- if(match):
- print match.group()
- PID.append(match.group())
- for i in PID:
- result = commands.getoutput("kill -9 "+i)
- dir_maker()
- print("1-start tcpdump; 2-kill tcpdump")
- ch = input()
- if (ch==1):
- start_dump()
- else:
- kill_proc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement