Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. import commands,re,time
  2. import subprocess
  3. TCPDUMP = "tcpdump "
  4. operation='ps | grep tcpdump'
  5. PATTERN = "\d+(?=\s)"
  6. DUMP_TIME = 300
  7. PATTERN_TIME = "[0-9]{2}:[0-9]{2}:[0-9]"
  8. PORTS = ["8080", "8070", "8060"]
  9. PATH = "/home/nirs/dump/service_"
  10. query_dir = "mkdir -p /home/nirs/dump/service_"
  11.  
  12. def get_time():
  13.     timest = re.findall(PATTERN_TIME,time.ctime())[0]
  14.     return timest
  15.  
  16. def dir_maker():
  17.     commands.getoutput("-u root mkdir /nirs/koibasta")
  18.     for port in PORTS:
  19.         result = commands.getoutput(query_dir+port)
  20.  
  21.  
  22. def start_dump():
  23.     for port in PORTS:
  24.         new_cmd = TCPDUMP+" -s 0 -w \""+PATH+port+"/date+%F--%H-%M.dump\" -G " + str(DUMP_TIME) + " -i eth0 'port "+port+"' &"
  25.         print new_cmd
  26.         result = subprocess.call(new_cmd,shell=True)
  27.                                
  28. def kill_proc():
  29.     result = commands.getoutput(operation)
  30.     ar = result.split("\n")
  31.     PID = []
  32.     for x in ar:
  33.         print(x)
  34.         match = re.search(PATTERN,x)
  35.         if(match):
  36.             print match.group()
  37.             PID.append(match.group())
  38.     for i in PID:
  39.             result = commands.getoutput("kill -9 "+i)
  40.        
  41. dir_maker()
  42. print("1-start tcpdump; 2-kill tcpdump")
  43. ch = input()
  44. if (ch==1):
  45.     start_dump()
  46. else:
  47.     kill_proc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement