Exemplo n.º 1
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    parser = argparse.ArgumentParser()
    parser.add_argument('--version', default=2, nargs='?', type=int)
    options = parser.parse_args()

    nfc = nfc_comm.NFC()
    readers = nfc.get_readers()
    if len(readers) == 0:
        print('Cannot find NFC reader.')
        return 2

    reader_status = nfc_comm.ReaderStatus(nfc.get_status_change()[0])
    if not reader_status.is_card_present():
        print('No card present.')
        return 2

    print('Found card.')

    cards = nfc_comm.get_cards(nfc)
    if len(cards) == 0:
        print('Card is not NTAG203.')
        return 2

    print('Card is NTAG203.')
    card = cards[0]

    with nfc_comm.Connection(nfc) as conn:
        if options.version == 1:
            defaults = packet.v1_defaults()
        else:
            defaults = packet.v2_defaults(1)
        pprint(defaults)
        card.write(conn, packet.encode(defaults))
Exemplo n.º 2
0
 def _send(self, protocol, packet_name, kwargs):
     packet = encode(packet_name,
                     protocol = protocol,
                     site_addr = self._site_addr,
                     bulb_addr = self._bulb_addr,
                     **kwargs)
     self._send_raw(packet)
Exemplo n.º 3
0
 def connectionMade(self):
     '''
     这里开始去发送账号姓名去请求登陆
     '''
     login_packet = game_pb2.Login()
     login_packet.name = 'tang'
     login_packet.password = '******'
     #self.transport.write(encode(101, login_packet))
     self.sendLine(encode(101, login_packet))
     print ("Connecton established to server")
Exemplo n.º 4
0
 def sendUdpPackage(self, message, dest_ip, dest_port, src_port):
     ethernet_packet = packet.encode(message, dest_ip, dest_port, src_port)
     packet_build = ethernet_packet.decode(
         "hex")  # Decode from hexadecimal to bytes
     self.my_socket.sendto(packet_build, (utils.getMyInterfaceName(), 0))
Exemplo n.º 5
0
 def run(self):
     while True:
         addr, packet = self.queue.get()
         #self.socket.sendto(bytearray(packet.encode(), 'iso-8859-15'), addr)
         self.socket.sendto(packet.encode(), addr)
         print("Sent packet {} to {}".format(packet, addr))
Exemplo n.º 6
0
 def sendData(self, cmd, data):
     self.factory.protocol.transport.write(encode(cmd, data))