Skip to content

Commit

Permalink
interface sniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Lingerhk committed Dec 7, 2016
1 parent 46a18d5 commit 795fdf4
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions net_attacking/interface_sniffer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -*- coding:utf-8 -*-

#
# A simple networking data packets
# sniff script using the famous PCAP library.
# Request:
# pip install impacket pacpy
# by s0nnet.
#


import sys
import getopt
import pcapy
from impacket.ImpactDecoder import EthDecoder


dev = 'eth0'
filter = 'arp'
decoder = EthDecoder()

# This function wills 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, 1024, 0, 100) # dev,buffer,mode,timeout

# Set pcap filter
pcap.setfilter(filter)

# Start sniffing
pcap.loop(0, handle_packet)

0 comments on commit 795fdf4

Please sign in to comment.