forked from waderwu/wsniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsniffer.py
35 lines (32 loc) · 1.17 KB
/
wsniffer.py
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
import socket
import traceback
from util import str2hex
from proto import Packet
sniffer = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(0x0003))
def sniff(ifrace='wlp5s0'):
sniffer.bind((ifrace, 0))
while True:
packet = sniffer.recvfrom(65565)
header = packet[0]
try:
p = Packet(str2hex(header))
# p.summary()
# if p.tcp:
# if not stream_index:
# print(stream_index)
# print(p.tcp.source_port)
# print(p.tcp.destination_port)
# print('here')
# stream_index = p.tcp.stream_index
# if p.tcp.stream_index == stream_index:
# if p.tcp.actual_data:
# f.write(p.tcp.actual_data)
except Exception:
print('error')
traceback.print_exc(file=open('error.log', 'w'))
# print('[---------------------------------------------------------------------------------]')
# tail = list(packet[1])
# tail[4] = str2hex(tail[4])
# print (str2hex(header))
# print(tail)
# break