Esempio n. 1
0
 def __init__(self, adr, key, port=DEFAULT_PORT):
     tmp = neonet.NrlConnection(adr, port)
     tmp.send(b"REMOTE_CONNECT")
     data = tmp.recv()
     if data == None:
         raise Exception("Connection Refused")
     elif data[:3] != b"OK=":
         #print(data)
         raise Exception("Remote Protocol Invalid")
     port = int(data[5:], 16)
     self.con = neonet.NrlSecureConnection(adr, port, key)
Esempio n. 2
0
 def __init__(self, adr, password, port=CMD_PORT):
     self.pss = crypt.shortstrhash(password)
     self.con = net.NrlConnection(adr, port)
     self.con.send(millis().to_bytes(8, 'little') +
                   crypt.sha512(hex(millis()) + self.pss))
     time.sleep(0.001)
     pkt = self.con.recv(8000)
     if pkt == None:
         raise Exception("Connection Refused")
     if len(pkt) != 4:
         raise Exception("Invalid Response Received: " + repr(pkt))
     self.con.port = int.from_bytes(pkt, 'little')
     self.queue = []
Esempio n. 3
0
 def __init__(self, adr, username, port=MSG_PORT):
     self.con = net.NrlConnection(adr, port)
     self.con.send(b'MSG_CON:' + username.encode())
     time.sleep(0.001)
     pkt = self.con.recv(8000)
     if pkt == None:
         raise Exception("Connection Refused")
     if len(pkt) != 4:
         raise Exception("Invalid Response Received: " + repr(pkt))
     self.con.port = int.from_bytes(pkt, 'little')
     self.con.send(bytes([CMD_READ_ALL]))
     self.ls_time = 0
     self.ls_index = 0
     self.list_text = []
     self.list_time = []
Esempio n. 4
0
def run_server(adr=net.address, port=CMD_PORT, password=""):
    password = crypt.shortstrhash(password)
    net.setup(adr)
    print("Starting command-issuing server at " + hex(net.address) + ":" +
          str(port))
    scon = net.NrlOpenPort(port)
    cons = []

    while True:
        for i in cons:
            if i.available():
                # update the connection because a packet is available
                packet = i.recv()
                try:
                    packet = crypt.decrypt1(packet, password)
                except:
                    continue
                timing = int.from_bytes(packet[:8], 'little')
                if timing < millis() and timing > millis() - 5000:
                    __cmdBcast(cons, packet[8:], password)
                try:
                    print(
                        hex(i.adr) + " : issued command: " +
                        packet[8:].decode())
                except:
                    print(hex(i.adr) + " : issued a binary command.")
        if scon.available():
            pk = scon.recv(0)
            remote_adr = pk[0]
            timing = int.from_bytes(pk[1][:8], 'little')
            if timing < millis() and timing > millis() - 5000:
                expected = crypt.sha512(hex(timing) + password)
                if expected == pk[1][8:]:
                    port = get_rand_port()
                    scon.send(pk[0], port.to_bytes(4, 'little'))
                    cons.append(net.NrlConnection(pk[0], port))
                    print("New connection from " + hex(pk[0]))
                else:
                    print("Connection failure from " + hex(pk[0]) +
                          ": bad cryptographic sequence.")
            else:
                print("Connection failure from " + hex(pk[0]) +
                      ": expired timing.")
        time.sleep(0.001)
Esempio n. 5
0
def run_server(adr=net.address, port=MSG_PORT):
    net.setup(adr)
    print("Starting messaging server at " + hex(net.address) + ":" + str(port))
    scon = net.NrlOpenPort(port)
    cons = []

    messages = []

    users = {}

    while True:
        for i in cons:
            if i.available():
                # update the connection because a packet is available
                packet = i.recv()
                cmd = packet[0]
                packet = packet[1:]
                if cmd == CMD_WRITE_MSG:
                    messages.append(
                        __msgBcast(cons, users[i.adr] + b": " + packet))
                    print((users[i.adr] + b": " + packet).decode())
                elif cmd == CMD_READ_ALL:
                    for i2 in messages:
                        __sendMsgPkt(i, i2)
                else:
                    print("Invalid packet receieved from " +
                          users[i.adr].decode() + " : " + repr(packet))
        if scon.available():
            pk = scon.recv(0)
            if pk[1].startswith(b'MSG_CON') and pk[1][7] == 58:
                port = get_rand_port()
                scon.send(pk[0], port.to_bytes(4, 'little'))
                cons.append(net.NrlConnection(pk[0], port))
                user = pk[1][8:]
                print("New connection from " + hex(pk[0]) + " [" +
                      user.decode() + "]")
                users[pk[0]] = user
                messages.append(__msgBcast(cons, user + b' is now online.'))
        time.sleep(0.001)