in progress

This commit is contained in:
sam 2021-04-21 13:45:47 +02:00
parent 2c8196051f
commit 50376aa518
4 changed files with 3002 additions and 45 deletions

2874
OSC3.py Executable file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,16 @@
# Nerves
A termeal version with led strip on raspberry pi
# Install
sudo apt install python3-pip
sudo pip3 install rpi_ws281x adafruit-circuitpython-neopixel
sudo python3 -m pip install --force-reinstall adafruit-blinka
sudo pip3 install scapy
# Based on previous work :
https://github.com/loloster/termeal
https://github.com/s0r00t/sniffeal

39
log.py Normal file
View File

@ -0,0 +1,39 @@
'''
Log in color from
https://stackoverflow.com/questions/287871/how-to-print-colored-text-in-terminal-in-python
usage :
import log
log.info("Hello World")
log.err("System Error")
'''
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = "\033[1m"
def disable():
HEADER = ''
OKBLUE = ''
OKGREEN = ''
WARNING = ''
FAIL = ''
ENDC = ''
def infog( msg):
print(OKGREEN + msg + ENDC)
def info( msg):
print(OKBLUE + msg + ENDC)
def warn( msg):
print(WARNING + msg + ENDC)
def err( msg):
print(FAIL + msg + ENDC)

118
nerves.py
View File

@ -3,47 +3,70 @@
'''
Nerves
v 0.1
A termeal version with led strip on raspberry pi
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.
v0.3
By Sam Neurohack
LICENCE : CC
'''
from OSC import OSCClient, OSCMessage
import log
print("")
print("")
log.infog("Nerves")
log.infog("v0.1b")
print("Loading...")
from OSC3 import OSCClient, OSCMessage
from sys import platform
from time import sleep
import types
import random
from scapy.all import *
import argparse
argsparser = argparse.ArgumentParser(description="Nerves v0.1")
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose output")
args = argsparser.parse_args()
verbose=args.verbose
client = OSCClient()
msg = OSCMessage()
counter = 0
def sendled(zzzport):
global counter
zzz = zzzport % 127
# zzz = led color
msg = OSCMessage()
msg.setAddress("/bhoreal/in")
msg.append(counter)
msg.append(zzz)
try:
client.sendto(msg, ('127.0.0.1', 9002))
msg.clearData()
except:
print 'Connection refused'
pass
sleep(0.001)
counter += 1
if counter > 63:
counter = 0
global counter
zzz = zzzport % 127
# zzz = led color
msg = OSCMessage()
msg.setAddress("/bhoreal/in")
msg.append(counter)
msg.append(zzz)
try:
client.sendto(msg, ('127.0.0.1', 9002))
msg.clearData()
except:
print('Connection refused')
pass
sleep(0.001)
counter += 1
if counter > 63:
counter = 0
@ -53,36 +76,41 @@ def print_summary(pkt):
ip_dst=pkt[IP].dst
if TCP in pkt:
tcp_sport=pkt[TCP].sport
tcp_dport=pkt[TCP].dport
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 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
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 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)
if ARP in pkt and pkt[ARP].op in (1,2):
print (" ARP")
sendled(67)
def handle_error(self,request,client_address): # All callbacks
def handle_error(self,request,client_address): # All callbacks
pass
sniff(iface='en0', prn=print_summary, store=0)
if platform == 'darwin':
sniff(iface='en0', prn=print_summary, store=0)
else:
sniff(iface='eth0', prn=print_summary, store=0)