This python example has a learning purpose and does not harm anyone.
import subprocess as sub
import re
def find_word(w):
return re.compile(r'\b({0})\b'.format(w), flags=re.IGNORECASE).search
p = sub.Popen(('sudo', 'tcpdump', '-l', '-s 0', '-vvv', '-n', '((udp port 67) and (udp[8:1] = 0x1))'),
stdout=sub.PIPE)
for row in iter(p.stdout.readline, b''):
if find_word(row):
print (row.split(' ')[-1])
elif find_word(row):
print (row.split(' ')[-1])
The result of my script ( I don't have inputs on this port).[mythcat@desk scripts]$ python3 dhcpreq.py
tcpdump: listening on ___, link-type EN10MB (Ethernet), capture size 262144 bytes
^CTraceback (most recent call last):
File "dhcpreq.py", line 10, in
for row in iter(p.stdout.readline, b''):
KeyboardInterrupt
0 packets captured
0 packets received by filter
0 packets dropped by kernel
[mythcat@desk scripts]$ vim dhcpreq.py