-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplesniffer.py
More file actions
executable file
·38 lines (33 loc) · 953 Bytes
/
simplesniffer.py
File metadata and controls
executable file
·38 lines (33 loc) · 953 Bytes
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
#!/usr/bin/env python3
import sys,os
import stack.rawif
import stack.process
#sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
class Unbuffered(object):
def __init__(self, stream):
self.stream = stream
def write(self, data):
self.stream.write(data)
self.stream.flush()
def writelines(self, datas):
self.stream.writelines(datas)
self.stream.flush()
def __getattr__(self, attr):
return getattr(self.stream, attr)
sys.stdout = Unbuffered(sys.stdout)
iface = "eth0"
if len(sys.argv) > 1:
iface = sys.argv[1]
raw = stack.rawif.bringupraw(iface=iface,promisc=True)
pe = stack.process.packetEngine()
while True:
# Read an Ethernet frame that's been sent to this device.
ethframe = stack.rawif.readrawethframe(raw)
try:
info,out = pe.processEth(ethframe)
for i in info: print(i)
print("============")
except stack.process.IgnorePacket as e:
pass
except BrokenPipeError as e:
exit(0)