2021-04-21 11:15:39 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
'''
|
|
|
|
Nerves
|
2021-04-21 11:45:47 +00:00
|
|
|
v 0.1
|
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
A termeal version with fiber optics on raspberry pi
|
2021-04-21 11:45:47 +00:00
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
goes with leds mode 0
|
2021-04-21 11:15:39 +00:00
|
|
|
|
|
|
|
sniff packets from interface en0 using python module scapy (2.3.1)
|
|
|
|
generate led color for bhoreal in usb midi mode depending on packet port number
|
|
|
|
send led number + color to PD patch boreal.pd
|
|
|
|
in OSC format : /bhoreal/in lednumber ledcolor
|
|
|
|
color is midi parameter so 0 to 127.
|
2021-04-21 11:45:47 +00:00
|
|
|
|
2021-04-21 11:15:39 +00:00
|
|
|
By Sam Neurohack
|
|
|
|
LICENCE : CC
|
2021-04-21 11:45:47 +00:00
|
|
|
|
2021-04-21 11:15:39 +00:00
|
|
|
'''
|
2021-04-21 11:45:47 +00:00
|
|
|
import log
|
|
|
|
|
|
|
|
print("")
|
|
|
|
print("")
|
|
|
|
log.infog("Nerves")
|
|
|
|
log.infog("v0.1b")
|
|
|
|
print("Loading...")
|
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
import adafruit_blinka.agnostic as agnostic
|
|
|
|
import board
|
|
|
|
import sys
|
|
|
|
|
|
|
|
print(
|
|
|
|
"Found system type: %s (sys.platform %s implementation %s) "
|
|
|
|
% (agnostic.board_id, sys.platform, sys.implementation.name)
|
|
|
|
)
|
|
|
|
|
2021-04-21 11:45:47 +00:00
|
|
|
from sys import platform
|
2021-04-21 11:15:39 +00:00
|
|
|
from time import sleep
|
|
|
|
import types
|
|
|
|
import random
|
|
|
|
from scapy.all import *
|
2021-04-26 00:34:15 +00:00
|
|
|
from threading import Thread
|
|
|
|
import traceback
|
2021-04-21 11:15:39 +00:00
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
import leds
|
|
|
|
import buttons
|
|
|
|
import ws
|
2021-04-21 11:45:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
# from Adafruit_GPIO import Platform
|
|
|
|
# print("Platform = ", Platform.platform_detect(), Platform.pi_version())
|
2021-04-21 11:45:47 +00:00
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
#print("board contents: ", dir(board))
|
2021-04-21 11:45:47 +00:00
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
|
|
|
|
nerves = [[0,7],[1,3],[2,9],[4,13],[5,11],[6,12],[8,10]]
|
|
|
|
influx = [0]*(len(nerves)*2)
|
|
|
|
print(influx)
|
2021-04-21 11:15:39 +00:00
|
|
|
|
|
|
|
counter = 0
|
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser(description="A Scanner Interface Darkly")
|
|
|
|
parser.add_argument("-i","--interface", help="interface to scan")
|
|
|
|
parser.add_argument("-x","--xcol",help="number of columns (8 by default)",type=int)
|
|
|
|
parser.add_argument("-y","--ycol",help="number of rows (8 by default)",type=int)
|
|
|
|
parser.add_argument("-f","--filter",help="tcpdump filter")
|
|
|
|
parser.add_argument("-c","--color",help="number of color",type=int)
|
|
|
|
parser.add_argument("-d","--display",help="type of side display",choices=["colors", "ports"])
|
|
|
|
parser.add_argument("-epi","--ephemeralportmin",help="ephemeral port min to exclude (32768 by default), set to 65536 to include all ports",type=int)
|
|
|
|
parser.add_argument("-epa","--ephemeralportmax",help="ephemeral port max to exclude (61000 by default)",type=int)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.xcol:
|
|
|
|
xmax=args.xcol
|
|
|
|
else:
|
|
|
|
xmax=8
|
|
|
|
|
|
|
|
if args.ycol:
|
|
|
|
ymax=args.ycol
|
|
|
|
else:
|
|
|
|
ymax=8
|
|
|
|
|
|
|
|
if args.color:
|
|
|
|
nbcolor=args.color
|
|
|
|
else:
|
|
|
|
nbcolor=15
|
|
|
|
|
|
|
|
if args.display:
|
|
|
|
sidedisplay=args.display
|
|
|
|
else:
|
|
|
|
sidedisplay="ports"
|
|
|
|
|
|
|
|
if args.ephemeralportmin:
|
|
|
|
ephemeralportmin = args.ephemeralportmin
|
|
|
|
else:
|
|
|
|
ephemeralportmin = 32768
|
|
|
|
|
|
|
|
if args.ephemeralportmax:
|
|
|
|
ephemeralportmax = args.ephemeralportmax
|
|
|
|
else:
|
|
|
|
ephemeralportmax = 61000
|
|
|
|
|
|
|
|
|
2021-04-21 11:15:39 +00:00
|
|
|
def sendled(zzzport):
|
2021-04-21 11:45:47 +00:00
|
|
|
global counter
|
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
#print("nerve",counter)
|
|
|
|
zzz = zzzport % leds.nbcolor # zzz = led color
|
|
|
|
|
|
|
|
influx[nerves[counter][0]] = zzz
|
|
|
|
influx[nerves[counter][1]] = zzz
|
|
|
|
#print("nerve",counter,"influx", influx)
|
2021-04-21 11:15:39 +00:00
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
leds.display(influx)
|
2021-04-21 11:15:39 +00:00
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
#print(len(nerves), "nerves")
|
|
|
|
if counter +1 == len(nerves):
|
|
|
|
counter = 0
|
|
|
|
else:
|
|
|
|
counter += 1
|
|
|
|
#print("next nerve", counter)
|
2021-04-21 11:15:39 +00:00
|
|
|
|
|
|
|
def print_summary(pkt):
|
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
if leds.mode == 0:
|
2021-04-21 11:15:39 +00:00
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
if IP in pkt:
|
|
|
|
ip_src=pkt[IP].src
|
|
|
|
ip_dst=pkt[IP].dst
|
|
|
|
|
|
|
|
|
|
|
|
if TCP in pkt:
|
|
|
|
tcp_sport=pkt[TCP].sport
|
|
|
|
tcp_dport=pkt[TCP].dport
|
|
|
|
|
|
|
|
if tcp_sport < 50000:
|
|
|
|
print (" IP src " + str(ip_src) + " TCP sport " + str(tcp_sport) )
|
|
|
|
sendled(tcp_sport)
|
|
|
|
if tcp_dport < 50000:
|
|
|
|
print (" IP dst " + str(ip_dst) + " TCP dport " + str(tcp_dport))
|
|
|
|
sendled(tcp_dport)
|
|
|
|
|
|
|
|
if UDP in pkt:
|
|
|
|
udp_sport=pkt[UDP].sport
|
|
|
|
udp_dport=pkt[UDP].dport
|
|
|
|
|
|
|
|
if udp_sport < 50000:
|
|
|
|
print (" IP src " + str(ip_src) + " UDP sport " + str(udp_sport) )
|
|
|
|
sendled(udp_sport)
|
|
|
|
|
|
|
|
if udp_dport < 50000:
|
|
|
|
print (" IP dst " + str(ip_dst) + " UDP dport " + str(udp_dport))
|
|
|
|
sendled(udp_dport)
|
|
|
|
|
|
|
|
|
|
|
|
if ARP in pkt and pkt[ARP].op in (1,2):
|
|
|
|
print (" ARP")
|
|
|
|
sendled(67)
|
2021-04-21 11:45:47 +00:00
|
|
|
|
2021-04-21 11:15:39 +00:00
|
|
|
|
|
|
|
|
2021-04-21 11:45:47 +00:00
|
|
|
def handle_error(self,request,client_address): # All callbacks
|
2021-04-21 11:15:39 +00:00
|
|
|
pass
|
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
'''
|
|
|
|
def main():
|
|
|
|
|
|
|
|
print("Testing leds...")
|
|
|
|
leds.cls()
|
|
|
|
leds.demo()
|
|
|
|
leds.cls()
|
|
|
|
|
2021-04-21 11:45:47 +00:00
|
|
|
if platform == 'darwin':
|
2021-04-26 00:34:15 +00:00
|
|
|
print("Running on", platform, "-> en0")
|
|
|
|
#sniff(iface='en0', prn=print_summary, store=0)
|
|
|
|
sniff(iface='en0', prn=print_summary, store=0,filter=args.filter)
|
|
|
|
|
2021-04-21 11:45:47 +00:00
|
|
|
else:
|
2021-04-26 00:34:15 +00:00
|
|
|
print("Running on", platform, "-> eth0")
|
2021-04-21 11:45:47 +00:00
|
|
|
sniff(iface='eth0', prn=print_summary, store=0)
|
2021-04-26 00:34:15 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
|
|
|
ws.Start(ws.serverIP, ws.wsPORT)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
ws_thread = Thread(target=ws.runforever, args=())
|
|
|
|
ws_thread.setDaemon(True)
|
|
|
|
ws_thread.start()
|
|
|
|
|
|
|
|
print("Launching buttons thread...")
|
|
|
|
buttons_thread = Thread(target=buttons.runforever, args=())
|
|
|
|
buttons_thread.setDaemon(True)
|
|
|
|
buttons_thread.start()
|
|
|
|
|
|
|
|
ws.sendWSall("/players Demo")
|
|
|
|
print("Testing leds...")
|
|
|
|
leds.cls()
|
|
|
|
leds.demo()
|
|
|
|
leds.cls()
|
|
|
|
|
|
|
|
# Start sniffing
|
|
|
|
leds.mode = 0
|
|
|
|
ws.sendWSall("/players Sniffing")
|
|
|
|
if platform == 'darwin':
|
|
|
|
print("Running on", platform, "-> en0")
|
|
|
|
#sniff(iface='en0', prn=print_summary, store=0)
|
|
|
|
sniff(iface='en0', prn=print_summary, store=0,filter=args.filter)
|
|
|
|
|
|
|
|
else:
|
|
|
|
print("Running on", platform, "-> eth0")
|
|
|
|
sniff(iface='eth0', prn=print_summary, store=0)
|
|
|
|
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
ws_thread.join()
|
|
|
|
buttons_thread.join()
|
2021-04-21 11:45:47 +00:00
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
if __name__ == '__main__':
|
2021-04-21 11:45:47 +00:00
|
|
|
|
2021-04-26 00:34:15 +00:00
|
|
|
main()
|