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))
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)
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")
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))
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))
def sendData(self, cmd, data): self.factory.protocol.transport.write(encode(cmd, data))