-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdprinter
87 lines (73 loc) · 1.76 KB
/
dprinter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Sun May 6 19:10:28 2018
@author: aslan.varoqua@duasamericasgroup.com
"""
import os
import subprocess, threading
from subprocess import Popen, PIPE, STDOUT
from flock import flock
import time
import datetime
now = datetime.datetime.now()
minusTwenty = now - datetime.timedelta(minutes = 10)
# globals
global start
start = "-param start=" + str(now.isoformat())
global finish
finish = "-param finish=" + str(minusTwenty.isoformat())
global pcap
pcap = "/src/p0f-input/input.pcap"
global processor
processor = "-f pig/examples/device_fingerprint.pig"
global mv
mv = 'mv'
global rm
rm = 'rm'
global pig
pig = 'pig'
global tcpdump
dump = 'tcpdump'
global seconds
seconds = '-G 30'
global iface
iface = '-ni eno2'
global queue
queue = '/p0f-queue/'
global p0f_input
p0f_input = '/p0f-input/input.pcap'
global landfill
landfill = '-s0 -w /p0f-input/input.pcap'
def tcpdump():
pcap = Popen([dump,iface,seconds,landfill],shell=True)
pcap.communicate()
pcap.kill()
def sweep():
pcap = Popen([rm,p0f_input,mv,queue + "*",p0f_input],shell=True)
pcap.communicate()
pcap.kill()
def send2pig():
try:
piggy = Popen([pig,processor,start,finish],shell=True)
piggy.communicate()
piggy.kill()
except:
print('could not access /p0f-input/input.pcap')
print('gracefully shutting down')
pass
def main():
## ========
## a message that there is a lock in place and exit.
lock = flock('/src/packetpig/pig.lock', True).acquire()
if lock:
try:
sweep()
except:
print("nothing in queue - making new dump 20min")
tcpdump()
send2pig()
else:
print('someone else is working here!')
if __name__ == "__main__":
main()