Skip to content

Commit

Permalink
Improved Display
Browse files Browse the repository at this point in the history
  • Loading branch information
RafayGhafoor committed Sep 1, 2017
1 parent cb3c198 commit 80c0990
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
11 changes: 4 additions & 7 deletions ptcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,19 @@ def main():
if not args.block:
# print "Calling blocker function - CLI MODE."
name = ptcl.show_active_dev()
ptcl.mac_and_host = dict(ptcl.mac_and_host)
ptcl.host_and_mac = dict(ptcl.host_and_mac)
dev_mac = int(raw_input("Please Enter Device Number: ")) - 1
ptcl.block_dev(ptcl.mac_and_host[name[dev_mac]])
ptcl.block_dev(ptcl.host_and_mac[name[dev_mac]])
print "%s has been blocked." % name[dev_mac].capitalize()


elif not args.unblock:
# print "Calling unblocker function - CLI MODE."
name = ptcl.show_active_dev()
ptcl.mac_and_host = dict(ptcl.mac_and_host)
ptcl.host_and_mac = dict(ptcl.host_and_mac)
dev_mac = int(raw_input("Please Enter Device Number: ")) - 1
ptcl.unblock_dev(ptcl.mac_and_host[name[dev_mac]])
ptcl.unblock_dev(ptcl.host_and_mac[name[dev_mac]])
print "%s has been unblocked." % name[dev_mac].capitalize()


import time
start_time = time.time()
main()
print("--- %s seconds ---" % (time.time() - start_time))
28 changes: 14 additions & 14 deletions router.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, mask="192.168.1.1", username="admin", password="admin"):
self.dev_hostname = [] # Devices Hostname
self.mac_address = [] # Devices Mac Address
self.active_dev = [] # Active Devices on Wi-Fi
self.mac_and_host = {} # Mac Addresses and Hostnames
self.host_and_mac = {} # Mac Addresses and Hostnames
self.session = requests.Session()
self.session.auth = (self.username, self.password)
self.session_key = ""
Expand Down Expand Up @@ -84,8 +84,8 @@ def show_dhcpinfo(self):
Shows DHCP information.
'''
self.get_dhcpinfo()
print tabulate({"HOSTNAME": self.dev_hostname, "MAC-ADDRESSES": self.mac_address}, headers=['HOSTNAME', 'Device-No.', 'MAC-ADDRESSES'], tablefmt='fancy_grid')
print "\n\n\t\tTotal Active Devices are [%s].\n\n" % len(self.dev_hostname)
print tabulate({"HOSTNAME": self.dev_hostname, "MAC-ADDRESSES": self.mac_address}, headers=['HOSTNAME', 'MAC-ADDRESSES'], tablefmt='fancy_grid')
print "\n\n\t\tTotal Devices Connected Today are: [%s].\n\n" % len(self.dev_hostname)


def get_stationinfo(self):
Expand All @@ -104,17 +104,17 @@ def show_active_dev(self):
'''
self.get_stationinfo()
self.get_dhcpinfo()
self.mac_and_host = tuple(zip(self.dev_hostname, self.mac_address))
self.host_and_mac = tuple(zip(self.dev_hostname, self.mac_address))
hostnames = []
print "-" * 20 + "STATION-INFO" + "-" * 20 + '\n'
display_list = []
count = 1
for k, v in self.mac_and_host:
for hostname, mac in self.host_and_mac:
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())
hostnames.append(k)
if active_clients in mac:
display_list.append([count, hostname, active_clients])
hostnames.append(hostname)
count += 1
print "-" * 52 + '\n'
print tabulate(display_list, headers=["DEVICE-NO.", "HOSTNAME", "MAC"], tablefmt="fancy_grid")
return hostnames


Expand Down Expand Up @@ -151,11 +151,11 @@ def set_hostname(self, custom_name, mac_address):
'''
self.get_dhcpinfo()
custom_hostnames = {}
self.mac_and_host = dict(zip(self.dev_hostname, self.mac_address))
for i in self.mac_and_host.items():
self.host_and_mac = dict(zip(self.dev_hostname, self.mac_address))
for i in self.host_and_mac.items():
if mac_address in i:
del(self.mac_and_host[i[0]])
self.mac_and_host[custom_name] = mac_address
del(self.host_and_mac[i[0]])
self.host_and_mac[custom_name] = mac_address


def reboot_router(self):
Expand Down

0 comments on commit 80c0990

Please sign in to comment.