def test_OptionList_update_by_index2(self): opt_list = self.gen_optionslist() opt_list[0] = options.options.short_value_to_object(57, 2000) self.assertEqual( opt_list, options.OptionList([ options.options.short_value_to_object(57, 2000), options.options.short_value_to_object(60, "android-dhcp-9"), options.options.short_value_to_object(12, "Galaxy-S9"), options.options.short_value_to_object( 55, [1, 3, 6, 15, 26, 28, 51, 58, 59, 43]), ]))
def gen_optionslist(self): return options.OptionList([ options.options.short_value_to_object(61, { 'hwtype': 1, 'hwaddr': "8c:45:00:1d:48:16" }), options.options.short_value_to_object(57, 1500), options.options.short_value_to_object(60, "android-dhcp-9"), options.options.short_value_to_object(12, "Galaxy-S9"), options.options.short_value_to_object( 55, [1, 3, 6, 15, 26, 28, 51, 58, 59, 43]) ])
def test_OptionList_del1(self): opt_list = self.gen_optionslist() del opt_list[0] self.assertEqual( opt_list, options.OptionList([ options.options.short_value_to_object(57, 1500), options.options.short_value_to_object(60, "android-dhcp-9"), options.options.short_value_to_object(12, "Galaxy-S9"), options.options.short_value_to_object( 55, [1, 3, 6, 15, 26, 28, 51, 58, 59, 43]), ]))
def test_OptionList_del2(self): opt_list = self.gen_optionslist() del opt_list[-1] self.assertEqual( opt_list, options.OptionList([ options.options.short_value_to_object( 61, { 'hwtype': 1, 'hwaddr': "8c:45:00:1d:48:16" }), options.options.short_value_to_object(57, 1500), options.options.short_value_to_object(60, "android-dhcp-9"), options.options.short_value_to_object(12, "Galaxy-S9"), ]))
def test_OptionList_update_by_index3(self): opt_list = self.gen_optionslist() opt_list[3] = options.options.short_value_to_object(57, 2000) self.assertEqual( opt_list, options.OptionList([ options.options.short_value_to_object( 61, { 'hwtype': 1, 'hwaddr': "8c:45:00:1d:48:16" }), options.options.short_value_to_object(60, "android-dhcp-9"), options.options.short_value_to_object(57, 2000), options.options.short_value_to_object( 55, [1, 3, 6, 15, 26, 28, 51, 58, 59, 43]), ]))
def test_OptionList_del3(self): opt_list = self.gen_optionslist() del opt_list[2] self.assertEqual( opt_list, options.OptionList([ options.options.short_value_to_object( 61, { 'hwtype': 1, 'hwaddr': "8c:45:00:1d:48:16" }), options.options.short_value_to_object(57, 1500), options.options.short_value_to_object(12, "Galaxy-S9"), options.options.short_value_to_object( 55, [1, 3, 6, 15, 26, 28, 51, 58, 59, 43]), ]))
def test_OptionsList_append2(self): opt_list = self.gen_optionslist() opt_list.append(options.options.short_value_to_object(57, 2000)) self.assertEqual( opt_list, options.OptionList([ options.options.short_value_to_object( 61, { 'hwtype': 1, 'hwaddr': "8c:45:00:1d:48:16" }), options.options.short_value_to_object(57, 2000), options.options.short_value_to_object(60, "android-dhcp-9"), options.options.short_value_to_object(12, "Galaxy-S9"), options.options.short_value_to_object( 55, [1, 3, 6, 15, 26, 28, 51, 58, 59, 43]), ]))
opt_json = opt_file.read() opts_dict = json.loads(opt_json) opts = [] for k, v in opts_dict.items(): opts.append(options.options.value_to_object({k: v})) except Exception as e: try: opts_dict = json.loads(args.options) opts = [] for k, v in opts_dict.items(): opts.append(options.options.value_to_object({k: v})) except Exception as e: logging.error( f"Unable to parse JSON options file {args.option}: {e}") exit(1) options_list = options.OptionList(opts) if client_addr := options_list.by_code(61): mac_addr = client_addr.value["client_identifier"]["hwaddr"] if verbosity: print(f"{CLIENT_NAME} - v{CLIENT_VER} - {utils.cur_datetime()}") c = client.DHCPClient(args.interface, send_from_port=args.port, send_to_port=args.target_port) try: lease = c.get_lease(mac_addr, broadcast=broadcast, options_list=options_list, server=server, relay=relay, verbose=verbosity)