Giter Club home page Giter Club logo

adafruit_blesniffer_python's Introduction

Python API for Bluefruit LE Sniffer

This repository contains the Python API for Adafruit's Bluefruit LE Sniffer, and our easy to use API wrapper.

It has been tested on the following platforms using Python 2.7:

  • OSX 10.10
  • Windows 7 x64
  • Ubuntu 14.04

Related Links

Bluefruit LE Sniffer product page: https://www.adafruit.com/product/2269 Bluefruit LE Sniffer Learning Guide: https://learn.adafruit.com/introducing-the-adafruit-bluefruit-le-sniffer/introduction

Sniffer Python Wrapper

Running sniffer.py in this folder on the Bluefruit LE Friend Sniffer Edition board will cause the device to scan for Bluetooth LE devices in range, and log any data from the selected device to a libpcap file (in logs/capture.pcap) that can be opened in Wireshark.

The current example does not enable live streaming of data directly into Wireshark via named pipes since this would require a pre-compiled utility for each platform, but it should be possible to implement this on your platform if required.

Using sniffer.py

To use sniffer.py, simply specify the serial port where the sniffer can be found (ex. COM14 on Windows, /dev/tty.usbmodem1412311 on OS X, /dev/ttyACM0 or Linux, etc.):

python sniffer.py /dev/tty.usbmodem1412311

Note: You will need to run python with sudo on Linux to allow the log file to be created, so sudo python sniffer.py /dev/ttyACM0, etc..

This will create a new log file and start scanning for BLE devices, which should result in the following menu:

$ python sniffer.py /dev/tty.usbmodem1412311
Logging data to logs/capture.pcap
Connecting to sniffer on /dev/tty.usbmodem1412311
Scanning for BLE devices (5s) ...
Found 2 BLE devices:

  [1] "" (14:99:E2:05:29:CF, RSSI = -85)
  [2] "" (E7:0C:E1:BE:87:66, RSSI = -49)

Select a device to sniff, or '0' to scan again
> 

Simply select the device you wish to sniff, and it will start logging traffic from the specified device.

Type CTRL+C to stop sniffing and quit the application, closing the libpcap log file.

NOTE: You may need to remove the sniffer and re-insert it before starting a new session if you see any unusual error messages running sniffer.py.

Requirements

This Python script was written and tested on Python 2.7.6, and will require that both Python 2.7 and pySerial are installed on your system.

adafruit_blesniffer_python's People

Contributors

ckuethe avatar ladyada avatar microbuilder avatar pizthewiz avatar speidy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_blesniffer_python's Issues

Compilation of Wireshark dissectors fails

Hi,

I need to run the sniffer / Wireshark combination on Linux, but there are no instructions whatsoever to compile the Wireshark packet dissectors. Just trying to compile the files results in several error messages that look like you are targeting an old Wireshark API.

Please update the source for a current version of Wireshark and provide makefiles to compile it into a library (or at least instructions on how to integrate it into the Wireshark source). Thanks very much.

Device.appendOrUpdate RSSI filter typo

When a new device is added via Device.appendOrUpdate, the RSSI check compares the newDevice against itself in the first logical expression (line 34). I believe it should compare the new device against the existing one (like it does in the second logical expression).

It looks like the new device is to be added if its RSSI is less than or greater than the existing device's (by some threshold). If so, wouldn't switching the two devices in the second logical expression make for a better filter? For example,

if (newDevice.RSSI < (existingDevice.RSSI - 5)) or (newDevice.RSSI > (existingDevice.RSSI+2)):

Scanning for BLE devices (5s) ... just repeats

Connecting to sniffer on COM16
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...

It doesn't display device list. In the logs I see:

02-Mar-2017 13:23:18 (FLE Standard Time) ERROR: 
Traceback (most recent call last):
  File "Adafruit_BLESniffer_Python-master\SnifferAPI\Packet.py", line 161, in getPacket
    packetList = self.decodeFromSLIP(timeout)
  File "Adafruit_BLESniffer_Python-master\SnifferAPI\Packet.py", line 138, in decodeFromSLIP
    raise Exceptions.UARTPacketError("Unexpected character after SLIP_ESC: %d." % serialByte)
UARTPacketError: Unexpected character after SLIP_ESC: 62.
02-Mar-2017 13:23:18 (FLE Standard Time) ERROR: CRASH
Traceback (most recent call last):
  File "Adafruit_BLESniffer_Python-master\SnifferAPI\Sniffer.py", line 150, in run
    self.runSniffer()
  File "Adafruit_BLESniffer_Python-master\SnifferAPI\Sniffer.py", line 175, in runSniffer
    self._continuouslyPipe()
  File "Adafruit_BLESniffer_Python-master\SnifferAPI\SnifferCollector.py", line 153, in _continuouslyPipe
    if not packet.valid:
AttributeError: 'NoneType' object has no attribute 'valid'

I'm using Windows 10 x64. FW 1111

Log: UART read timeout

I used the BLE sniffer to sniff the packets between a BLE device and a phone during paring and connection. But everytime I tried to connect the BLE device and typed PIN in the phone for pairing, the sniffer was just stuck. Then I checked the log saying UART read timeout (2 seconds). I used nRF connect in my phone to connect to the BLE device which is a WSTK mainboard with Mighty Gecko. Any idea about this error?
Thanks.

Get Device State (Blue/Red/Yellow lights)

Normally, when I start the sniffer.py and connect, the device goes through a cycle of blue flashing (I assume 'ready') and yellow flashing (I assume scanning) and red is off. Once connected, I get red and yellow flashing (connected). When the other device connects, I get all three lights flashing, blue yellow red.

But, sometimes, the python script things it has connected, but I continue to get a blue/yellow flashing and it never really connects. The only way I can fix this is to restart the code. I'd like to re-run the setup in this case, but I can't tell when it gets into this state. I even get packets in the dumpPackets code.

Is there a way to get a status from the device regarding these LEDs? I would then be able to programmatically reset things.

Thanks.

serial.serialutil.SerialException: Attempting to use a port that is not open

Trying to use sniffer.py on macOS Sierra (10.12.1) is giving errors:

$ sudo python sniffer.py /dev/tty.usbserial-DJ00IO3W
Password:
Logging data to logs/capture.pcap
Connecting to sniffer on /dev/tty.usbserial-DJ00IO3W
Scanning for BLE devices (5s) ...
Traceback (most recent call last):
  File "sniffer.py", line 156, in <module>
    devlist = scanForDevices()
  File "sniffer.py", line 50, in scanForDevices
    mySniffer.scan()
  File "/Users/itemir/Temp/Adafruit_BLESniffer_Python/SnifferAPI/Sniffer.py", line 62, in scan
    self._startScanning()
  File "/Users/itemir/Temp/Adafruit_BLESniffer_Python/SnifferAPI/SnifferCollector.py", line 206, in _startScanning
    self._packetReader.sendScan()
  File "/Users/itemir/Temp/Adafruit_BLESniffer_Python/SnifferAPI/Packet.py", line 186, in sendScan
    self.sendPacket(REQ_SCAN_CONT, [], timeout)
  File "/Users/itemir/Temp/Adafruit_BLESniffer_Python/SnifferAPI/Packet.py", line 183, in sendPacket
    self.uart.writeList(packetString, timeout)
  File "/Users/itemir/Temp/Adafruit_BLESniffer_Python/SnifferAPI/UART.py", line 73, in writeList
    nBytes = self.ser.write(array)
  File "/Library/Python/2.7/site-packages/serial/serialposix.py", line 497, in write
    raise portNotOpenError
serial.serialutil.SerialException: Attempting to use a port that is not open

ble-sniffer-osx from Roland King works, so it is not an OS issue nor a hardware issue.

It also looks like there have been others who ran into this issue. See the following thread: https://forums.adafruit.com/viewtopic.php?f=22&t=82839&sid=643613138ca6829f5444dd61c1cabc7d&start=15 (Workaround mentioned there, to install 2.3 FTDI driver, does also not work).

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.