Git Product home page Git Product logo

python_sniffer's Introduction

Python_sniffer

This simple python class provides a network sniffer. It uses the scapy libraries.

Description

The scapy's method "sniff" has the characteristic that it locks the execution of the code. With this class you can run the sniffer in a new thread without locking the natural execution of the code.

Usage

from Sniffer import Sniffer
from Iface import Iface

iface = Iface('wlan0')

# This is an optional command
iface.set_mtu(2500)

sniffer = Sniffer(iface)
sniffer.start()
# Some instruction
sniffer.stop()

The constructor accepts also callback functions then you can use the scapy methods on sniffed packet:

def print_packet(*args, **kwargs):
  print("This message is printed every time that sniffer intercepts a packet.")
  print(kwargs)
  args[0].show()

def finished(*args, **kwargs):
  print("This message is printed when you stop the sniffer.")

iface = Iface('wlan0')
prn_kwargs = {'var': 0}
sniffer = Sniffer(iface, callback_prn=print_packet, callback_stop=finished, callback_prn_kwargs=prn_kwargs)
sniffer.start()
while(sniffer.get_started_flag() is False):
    pass
# Some instruction
sniffer.stop()

Prerequisites

This class is written with Python3. Then you need to install scapy in python3 enviroment and run script with sudo command.

Other

You can have only one instance of sniffer. At now, if you call .stop method you have to create another instance of sniffer if you want re-run it.

iface = Iface('wlan0')
sniffer = Sniffer(iface)
sniffer.start()
sniffer.stop()
sniffer = Sniffer(iface)
sniffer.start()

python_sniffer's People

Contributors

lucadivit avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.