Best Python code snippet using lisa_python
cli.py
Source:cli.py
...46 47def _notify_error_and_finish(message, cliparser):48 cliparser.print_help() 49 cliparser.error(message)50def _send_packets(macs, broadcast, destination, port, quiet_mode):51 """Send a magic packet to each mac in *macs*, this function tries52 to deliver even if some of the macs are faulty in anyway.53 Returns False in case of any error on any of the *macs*, otherwise True.54 """55 no_errors = True56 for mac in macs:57 try:58 awake.wol.send_magic_packet(mac, broadcast, destination, port)59 except ValueError:60 exep = awake.utils.fetch_last_exception()61 sys.stderr.write('ERROR: %s\n' % exep.args[0])62 no_errors = False63 else:64 if not quiet_mode:65 if destination is None:66 destination = broadcast67 print('Sending magic packet to %s with broadcast %s MAC %s port %d' % \68 (destination, broadcast, mac, port))69 return no_errors70def main():71 cliparser = _build_cliparser()72 options, args = cliparser.parse_args()73 try:74 macs = _get_macs(options, args)75 except Exception:76 exep = awake.utils.fetch_last_exception()77 _notify_error_and_finish(exep.args[0], cliparser)78 if macs:79 if not _send_packets(macs, options.broadcast,80 options.destination,81 options.port, options.quiet_mode):82 sys.exit(1)83 else:84 _notify_error_and_finish('Unable to acquire any mac address',...
client.py
Source:client.py
...33 except KeyboardInterrupt:34 print('Cancelled')35 async def _run_test(self) -> None:36 recv_task = await curio.spawn(self._recv_packets)37 await self._send_packets()38 print('All packets sent')39 try:40 await curio.timeout_after(self._timeout, recv_task.join())41 except curio.TaskTimeout:42 await recv_task.cancel()43 async def _send_packets(self) -> None:44 for nr in range(self._packet_count):45 await self._sock.sendto(make_packet(nr, 1500), self._target,)46 async def _recv_packets(self) -> None:47 while True:48 data, addr = await self._sock.recvfrom(4096)49 print('Received:', data)50 self.packets_received += 151 if self.packets_received >= self._packet_count:52 break53def make_packet(id_: int, size: int) -> bytes:54 body = ''.join(55 random.choice(string.ascii_lowercase) for i in range(size - 2)56 ).encode('ascii')57 return struct.pack('!H', id_) + body...
traceroute.py
Source:traceroute.py
...17 received_address = ''18 while (self._ttl < self._args.hops and19 received_address != self._address):20 self._cli.add_ttl_number(self._ttl)21 name, received_address = self._send_packets()22 self._sequence = self._make_sequence()23 self._cli.add_line(name + '\n')24 self._ttl += 125 return self._cli26 @debug_decorator27 def _make_sequence(self):28 return list(map(lambda n: n + self._args.query_number,29 self._sequence))30 @debug_decorator31 def _send_packets(self):32 name = ''33 received_address = ''34 for i in range(self._args.query_number):35 icmp = ICMP(self._sequence[i], self._args)36 self._socket.set_socket_options(self._ttl)37 packet = icmp.get_packet()38 packet_tracer = PacketTracer(self._socket, self._sequence,39 self._cli, self._args.interval)40 name, received_address = packet_tracer.trace_packet(packet, name)41 return name, received_address42def main():43 args = Arguments()44 cli = CommandLineInterface(args)45 socket = SocketWrapper(args)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!