Exemplo n.º 1
0
def main(argv):
    try:
        (logFile, logLevel, listenPort, spoofFavicon, killSessions, targetIp, iface, redirect, routerIp, cutNet,
        scan) = parseOptions(argv)
        if scan != "":
            Scanner().run(scan)
            sleep(2)
            sys.exit()
        else:
            enable_forward()
            p1 = multiprocessing.Process(target=Strip().start, args=(logFile, logLevel, listenPort, spoofFavicon, killSessions))
            p2 = multiprocessing.Process(target=final_spoof, args=(routerIp, targetIp))
            p1.start()
            p2.start()
            try:
                if cutNet and targetIp:
                    cut_queue()
                elif redirect and targetIp:
                    redirect_queue()
                elif iface:
                    sniff(iface)
                else:
                    Strip().usage()
            except Exception:
                print("[-] Error in Final Comparision")
    except KeyboardInterrupt:
        subprocess.call("iptables --flush", shell=True)
        p1.stop()
        p2.stop()
        sleep(1)
        sys.exit()
Exemplo n.º 2
0
def parseOptions(argv):
    logFile = 'sslstrip.log'
    logLevel = logging.WARNING
    listenPort = 80
    spoofFavicon = False
    killSessions = False
    redirect = ""
    routerIp = "192.168.1.1"
    targetIp = ""
    iface = ""
    cutNet = False
    scan = ""

    try:
        opts, args = getopt.getopt(argv, "hw:l:t:rg:i:psafkc",
                                   ["help", "write=", "post", "ssl", "all", "listen=",
                                    "favicon", "killsessions", "target-ip=", "redirect=", "iface=", "scan=", "cut-net", "gate="])

        for opt, arg in opts:
            if opt in ("-h", "--help"):
                Strip().usage()
                sys.exit()
            elif opt in ("-w", "--write"):
                logFile = arg
            elif opt in ("-p", "--post"):
                logLevel = logging.WARNING
            elif opt in ("-s", "--ssl"):
                logLevel = logging.INFO
            elif opt in ("-a", "--all"):
                logLevel = logging.DEBUG
            elif opt in ("-l", "--listen"):
                listenPort = arg
            elif opt in ("-f", "--favicon"):
                spoofFavicon = True
            elif opt in ("-k", "--killsessions"):
                killSessions = True
            elif opt in ("-t", "--target-ip"):
                targetIp = arg
            elif opt in ("-r", "--redirect"):
                redirect = True
            elif opt in ("-i", "--iface"):
                iface = arg
            elif opt in ("-c", "--cut-net"):
                cutNet = True
            elif opt in ("--scan"):
                scan = arg
            elif opt in ("-g", "--gate"):
                routerIp = arg
        return (logFile, logLevel, listenPort, spoofFavicon, killSessions, targetIp, iface, redirect, routerIp, cutNet, scan)

    except getopt.GetoptError:
        Strip().usage()
        print()
        sys.exit(2)
def testFade(count):
  print( "*** testFade ***" )

  strip = Strip(150)
  while count > 0:
    strip.clear([255, 0, 255])
    strip.send()
    for _i in range(10):
      time.sleep(1)
      strip.fade(0.6)
      strip.send()
    count -= 1

  strip.artnet.close()
Exemplo n.º 4
0
    def __init__(self, a_midi_file, hand):
        self.midi_file = a_midi_file
        self.color_rw = mColor(0, 255, 0)
        self.color_rb = mColor(255, 0, 255)
        self.color_lw = mColor(255, 0, 0)
        self.color_lb = mColor(0, 255, 255)

        # Create the strip
        self.my_strip = Strip()

        # preprocessing
        self.msgs = list()
        id_track = 0
        time_track = 0
        for a_track in self.midi_file.tracks:
            if (a_track.name == "Left" and (hand == 'b' or hand == 'l')) or\
                (a_track.name == "Right" and (hand == 'b' or hand == 'r')):
                for a_msg in a_track:
                    time_track += a_msg.time
                    self.msgs.append(Message(id_track, a_msg, time_track))
                id_track += 1
                time_track = 0  # Reset time for next rack

        self.msgs.sort(key=lambda x: x.time)

        print("{} messages to play!".format(len(self.msgs)))
Exemplo n.º 5
0
def scan():
    strip = Strip(150)

    while True:
        strip.artnet.addr = [("192.168.89.255", 6454)]
        devices = strip.artnet.poll()
        print(devices)
        for i, device in enumerate(devices):
            strip.artnet.addr = [device]
            strip.clear(color[i])
            strip.send()
            print("-> ", device, color[i], colornames[i])
            time.sleep(.1)
        time.sleep(10)
Exemplo n.º 6
0
    def __init__(self, led_spacing, strip_spacing):
        """
            Big daddy cube
        """    

        # The vertices of the cube
        vertices = np.array([
            (1, -1, -1),
            (1, 1, -1),
            (-1, -1, -1),
            (-1, 1, -1),
            (1, -1, 1),
            (1, 1, 1),
            (-1, 1, 1),
            (-1, -1, 1)
        ]).astype(float)

        # TODO: Set cube length and orientation
        edge_length = 2

        # An eulerian tour around a cube with two strips per edge
        # Elements are from-to tuples that map to indices in the vertices array
        route = np.array([(0, 1), (1, 0), (0, 2), (2, 0), (0, 4), (4, 5), (5, 1), (1, 3), (3, 1), (1, 5), (5, 4), (4, 7), (7, 2), (2, 3), (3, 2), (2, 7), (7, 6), (6, 3), (3, 6), (6, 5), (5, 6), (6, 7), (7, 4), (4, 0)])

        # Create strips in the order they should be laid
        pixels_per_edge = int(float(edge_length)/led_spacing)
        self.strips = []
        for path in route:
            start = vertices[path[0]]
            end = vertices[path[1]]

            # A hacky(ish) way to offset strips so they are not on top of each other
            sign = 1 if path[0] > path[1] else -1
            offset = 0.5*strip_spacing*sign
            start += offset
            end += offset

            direction = end - start

            self.strips.append(Strip(start, direction, led_spacing, pixels_per_edge))
Exemplo n.º 7
0
import time
import math
import sys

IP = "192.168.0.230"
PORT = 3000
LENGTH = 174

mode = 0
brightness = 100
if len(sys.argv) > 1:
    brightness = int(sys.argv[1])
if len(sys.argv) > 2:
    mode = int(sys.argv[2])

s = Strip(LENGTH, IP, PORT)


def gauss(_pos, _color):
    for i in range(15):
        v = list(
            map(lambda x: int(x * brightness * math.exp(-0.5 * (i - _pos)**2)),
                _color))
        s.set(i, *v)


def rgbow(p):
    return [dist(p + 1 / 3) + dist(p - 2 / 3), dist(p), dist(p - 1 / 3)]


def dist(x):
Exemplo n.º 8
0
    import time
    from strip import Strip

    # - - - - -
    # uncomment these two lines to look under the hood.
    #print(get_state())
    #exit()
    # Currently it returns one of these for each node: {'online','bad_sensor','offline'}
    # so just check for those.
    # - - - - -

    LENGTH = 8

    BRIGHTNESS = 0.03

    with Strip(LENGTH, input('PORT=')) as strip:
        while True:
            try:
                state = get_state()
                for k in range(LENGTH):
                    strip.clear_bit(k)
                print('- - - - -')
                print(datetime.now())
                nodes = sorted(state.keys())
                nodes = nodes[:LENGTH]
                #                nodes = reversed(nodes)
                for k, node in enumerate(nodes):
                    print(node, state[node])

                    if 'online' == state[node]:
                        strip.set_bit(k, color=[0, BRIGHTNESS, 0])
Exemplo n.º 9
0
    return 255
  if count < period26:
    count -= period16
    return 255 * (period16 - count) / period16
  if count < period46:
    return 0
  if count < period56:
    count -= period46
    return 255 * count / period16
  if count < period:
    return 255
  return 0

def rainbow(count):
  r = getColorValue2(count)
  g = getColorValue2(count - period13)
  b = getColorValue2(count - period23)
  return [r, g, b]

count = 0
strip = Strip(150)
strip.clear()
strip.send()
while True:
  strip.clear(rainbow(count))
  strip.send()
  count += 1
  if count >= period:
    count -= period
  time.sleep(.1)
Exemplo n.º 10
0
# Single-pixel chase light
#
# Stanley H.I. Lio
# [email protected]
# OCN318, S18

import time, math
from strip import Strip

DISP_LENGTH = 8

with Strip(DISP_LENGTH, input('PORT=')) as strip:
    while True:
        try:
            for k in range(DISP_LENGTH):
                strip.set_bit(k, (0, .2, .2))
                strip.set_bit(DISP_LENGTH - k - 1, (.1, .1, 0))
                time.sleep(0.01)
                strip.clear_bit(k)
                strip.clear_bit(DISP_LENGTH - k - 1)
        except KeyboardInterrupt:
            break
Exemplo n.º 11
0
#controller.set_number_of_leds(2, 150)
controller.set_number_of_leds(1, 300)

controller.change_white_brightness(63)
controller.change_color_brightness(63)
controller.set_speed(255)
controller.set_color(0, 0, 0)
controller.set_pattern('STATIC')

values = controller.sync()
print(values)

if not values['power']:
    controller.toggle_on_off()

s = Strip(values['leds_per_segment'], scale=1)

print("Demo 1...")
for pixel in range(0, values['leds_per_segment']):
    print(" Pixel %d" % pixel)

    s.reset(0, 0, 0)
    s.set_led_color(pixel - 3, 32, 0, 0)
    s.set_led_color(pixel - 2, 0, 64, 0)
    s.set_led_color(pixel - 1, 0, 0, 128)
    s.set_led_color(pixel + 0, 255, 0, 0)
    s.set_led_color(pixel + 1, 0, 128, 128)
    s.set_led_color(pixel + 2, 0, 64, 64)
    s.set_led_color(pixel + 3, 0, 32, 0)

    # Send it more than once to control speed (yeah bad way)
Exemplo n.º 12
0
#================================================
#
#    INIT / CONFIG
#
#------------------------------------------------
config = configparser.ConfigParser()
if os.path.isfile('../config/settings.ini'):
    config.read('../config/settings.ini')
else:
    print("Error: no \"config/settings.ini\" file. Use \"config/settings.ini.sample\" as template.")
    exit()
frame_rate = config.getint("global", "frame_rate")
auto_list = config.getboolean("global", "auto_list", fallback=True)
strips = [
    Strip(config.getint("strips", "strip_a_len"), 18, 10, 0),
    Strip(config.getint("strips", "strip_b_len"), 13, 11, 1),
]
global_alive = True


def render(strips):
    global global_alive
    global frame_rate

    while global_alive:
        for each in strips:
            each.step()
            sleep(0.5 / frame_rate)

Exemplo n.º 13
0
from flask import Flask, request
from strip import Strip
from validator import valid_data, valid_status, valid_color, valid_intensity

app = Flask(__name__)

strip = Strip()


@app.route("/")
def default():
    return 'stana goshoooo\n'


@app.route("/strip", methods=['GET'])
def get():
    return {
        "status": strip.status,
        "color": strip.color,
        "intensity": strip.intensity
    }


@app.route("/strip", methods=['POST'])
def set():
    data = request.get_json()
    if not valid_data(data.keys()):
        return {"error": "Invalid data keys"}

    if 'intensity' in data:
        if valid_intensity(data['intensity']):
def test1():
  print( "*** test1 ***" )

  strip = Strip(150)

  strip.clear([255, 0, 0])
  strip.set(0, [0, 255, 0])
  strip.set(strip.length - 1, [0, 0, 255])
  strip.artnet.send(strip)
  time.sleep(3)

  strip.clear([0, 255, 0])
  strip.set(0, [255, 0, 0])
  strip.set(strip.length - 1, [0, 0, 255])
  strip.artnet.send(strip)
  time.sleep(3)

  strip.clear([0, 0, 255])
  strip.set(0, [255, 0, 0])
  strip.set(strip.length - 1, [0, 255, 0])
  strip.artnet.send(strip)
  time.sleep(3)

  strip.artnet.close()
Exemplo n.º 15
0
if __name__ == '__main__':
    # Process arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('-t', '--test', action='store_true', help='runs test')
    parser.add_argument('-p', '--port', action='store_const', const=50051)
    args = parser.parse_args()

    # Create server
    host = '[::]:%s' % parser.parse_args(['--port']).port
    executor = futures.ThreadPoolExecutor(max_workers=2)
    server = grpc.server(executor)
    server.add_insecure_port(host)
    service_pb2_grpc.add_HardwareCommandServicer_to_server(HardwareServicer(), server)

    # Create NeoPixel object with appropriate configuration
    strip = Strip()

    if args.test:
        print('Running test', flush=True)
        strip.test()
        exit(0)

    try:
        server.start()
        print('Running hardware server on %s' % host, flush=True)
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
        strip.clear()
        server.stop(0)
Exemplo n.º 16
0
#!/usr/bin/python3
import numpy as np
import sent2vec
from scipy import spatial
from strip import Strip
from collections import defaultdict


def cosine(u, v):
    return 1 - spatial.distance.cosine(u, v)


train_raw = 'en-train.txt'
#[ { 's1': , 's2': , 'score': } ]
train_pairs = []
s = Strip()
with open(train_raw) as f:
    for line in f:
        if line:
            temp = line.split('\t')
            train_pairs.append({
                'sen1': s.removeALL(temp[0]),
                'sen2': s.removeALL(temp[1]),
                'score': float(temp[2].strip('\n'))
            })

model = sent2vec.Sent2vecModel()
model.load_model('model.bin')

# find cosine similarity between the pairs
files = ['0-1', '1-2', '2-3', '3-4', '4-5']