Skip to content

Commit

Permalink
Fixed hostname duplication disappearance from dictionary (data struct…
Browse files Browse the repository at this point in the history
…ure) by using Tuple
  • Loading branch information
RafayGhafoor committed Aug 18, 2017
1 parent 9cc9de7 commit 8647719
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[User-Aliases]
[Router-Auth]
username = admin
password = admin
mask = 192.168.1.1
6 changes: 3 additions & 3 deletions ptcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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):
'''
Expand All @@ -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):
'''
Expand Down

0 comments on commit 8647719

Please sign in to comment.