From 86477199f6a2e541e0f63f6f27bde2c12fb173f6 Mon Sep 17 00:00:00 2001 From: Rafay Ghafoor Date: Fri, 18 Aug 2017 12:29:19 +0500 Subject: [PATCH] Fixed hostname duplication disappearance from dictionary (data structure) by using Tuple --- config.ini | 5 +++++ ptcl.py | 6 +++--- router.py | 8 ++++---- 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 config.ini diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..5c74e4d --- /dev/null +++ b/config.ini @@ -0,0 +1,5 @@ +[User-Aliases] +[Router-Auth] +username = admin +password = admin +mask = 192.168.1.1 diff --git a/ptcl.py b/ptcl.py index 5564080..a188ed8 100755 --- a/ptcl.py +++ b/ptcl.py @@ -13,7 +13,7 @@ # "asad": "A0:32:99:AB:33:31", # "hhp": "44-1C-A8-73-A3-17" # } -config[User-Aliases] = {} +config['User-Aliases'] = {} def main(): parser = argparse.ArgumentParser(description="Control PTCL router from command-line.") @@ -82,9 +82,9 @@ def main(): if password: DEFAULT['password'] = password config['Router-Auth'] = DEFAULT - + print DEFAULT with open('config.ini', 'w') as configfile: - config.write(configfile) + config.write(DEFAULT) elif args.show_active == '.': # print "Calling show_active Function" diff --git a/router.py b/router.py index efe93a1..2943278 100755 --- a/router.py +++ b/router.py @@ -102,11 +102,11 @@ def show_active_dev(self): ''' self.get_stationinfo() self.get_dhcpinfo() - self.mac_and_host = dict(zip(self.dev_hostname, self.mac_address)) + self.mac_and_host = tuple(zip(self.dev_hostname, self.mac_address)) hostnames = [] print "-" * 20 + "STATION-INFO" + "-" * 20 + '\n' count = 1 - for k, v in self.mac_and_host.iteritems(): + for k, v in self.mac_and_host: for active_clients in self.active_dev: if active_clients in v: print "(%s) %s%s\n" % (count, k + ":" + ' ' * (30 - len(k) - len(str(count))), active_clients.upper()) @@ -140,7 +140,7 @@ def show_blocked_dev(self): if not i.find("input"): if Router.mac_adr_regex.search(i.text): print i.text + '\n' - + def set_hostname(self, custom_name, mac_address): ''' @@ -154,7 +154,7 @@ def set_hostname(self, custom_name, mac_address): if mac_address in i: del(self.mac_and_host[i[0]]) self.mac_and_host[custom_name] = mac_address - + def reboot_router(self): '''