Exemplo n.º 1
0
def client_main(ck):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind(('', Settings.MY_PORT))

    while True:
        data, addr = s.recvfrom(300)

        mac = int.from_bytes(data[0:6], byteorder=Settings.MAC_BYTEORDER)
        k = int.from_bytes(data[6:7], byteorder='little', signed=True)
        if k <= 0 or len(data) < 7 + k + Settings.TIMESTAMP_LENGTH:
            ck.incorrect += 1
            continue
        try:
            name = data[7:7 + k].decode('utf-8')
        except UnicodeDecodeError:
            ck.incorrect += 1
            continue

        t = int.from_bytes(data[7 + k:7 + k + Settings.TIMESTAMP_LENGTH],
                           byteorder=Settings.DATA_BYTEORDER)

        c = ConnectPack(mac, name)

        ck.add(c)
        ck.to_print.put(
            "Receive msg. MAC: {0} name: {1} time: {2} addr: {3}".format(
                c.mac_str, c.name, t, addr))
Exemplo n.º 2
0
def server_main_spam(ck):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind(('', 0))
    s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

    c = ConnectPack.make_localhost_pack()
    header = c.mac_bytes_be
    header += len(c.name).to_bytes(1, byteorder='little')
    header += c.name.encode()

    while True:
        header = randint(0, 255**1000).to_bytes(1000, byteorder='big')
        s.sendto(header, ('<broadcast>', Settings.MY_PORT))
        # ck.to_print.put("Send spam msg.")
        time.sleep(Settings.TIME_PAUSE_SPAM)
Exemplo n.º 3
0
def server_main_spam(ck):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind(('', 0))
    s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

    c = ConnectPack.make_localhost_pack()
    header = c.mac_bytes_be
    header += len(c.name).to_bytes(1, byteorder='little')
    header += c.name.encode()

    while True:
        header = randint(0, 255 ** 1000).to_bytes(1000, byteorder='big')
        s.sendto(header, ('<broadcast>', Settings.MY_PORT))
        # ck.to_print.put("Send spam msg.")
        time.sleep(Settings.TIME_PAUSE_SPAM)
Exemplo n.º 4
0
def server_main(ck):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind(('', 0))
    s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

    c = ConnectPack.make_localhost_pack()
    header = c.mac_bytes_be
    header += len(c.name).to_bytes(1, byteorder='little')
    header += c.name.encode()

    while True:
        t = int(time.time())
        data_time = t.to_bytes(Settings.TIMESTAMP_LENGTH, byteorder=Settings.DATA_BYTEORDER)

        s.sendto(header + data_time, ('<broadcast>', Settings.MY_PORT))

        ck.to_print.put("Send msg. My mac: {0} name: {1} time: {2}".format(c.mac_str, c.name, t))

        time.sleep(Settings.TIME_PAUSE_SENDING)
Exemplo n.º 5
0
def server_main(ck):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind(('', 0))
    s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

    c = ConnectPack.make_localhost_pack()
    header = c.mac_bytes_be
    header += len(c.name).to_bytes(1, byteorder='little')
    header += c.name.encode()

    while True:
        t = int(time.time())
        data_time = t.to_bytes(Settings.TIMESTAMP_LENGTH,
                               byteorder=Settings.DATA_BYTEORDER)

        s.sendto(header + data_time, ('<broadcast>', Settings.MY_PORT))

        ck.to_print.put("Send msg. My mac: {0} name: {1} time: {2}".format(
            c.mac_str, c.name, t))

        time.sleep(Settings.TIME_PAUSE_SENDING)