forked from balle/python-network-hacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsniffer.py
executable file
·45 lines (34 loc) · 817 Bytes
/
sniffer.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
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python3
import sys
import getopt
import pcapy
from impacket.ImpactDecoder import EthDecoder
dev = "enp3s0f1"
filter = "arp"
decoder = EthDecoder()
# This function will be called for every packet
# and just print it
def handle_packet(hdr, data):
print(decoder.decode(data))
def usage():
print(sys.argv[0] + " -i <dev> -f <pcap_filter>")
sys.exit(1)
# Parsing parameter
try:
cmd_opts = "f:i:"
opts, args = getopt.getopt(sys.argv[1:], cmd_opts)
except getopt.GetoptError:
usage()
for opt in opts:
if opt[0] == "-f":
filter = opt[1]
elif opt[0] == "-i":
dev = opt[1]
else:
usage()
# Open device in promisc mode
pcap = pcapy.open_live(dev, 1500, 0, 100)
# Set pcap filter
pcap.setfilter(filter)
# Start sniffing
pcap.loop(0, handle_packet)