Skip to content

Commit

Permalink
Edits
Browse files Browse the repository at this point in the history
  • Loading branch information
RafayGhafoor committed Jul 25, 2017
1 parent 61892aa commit 10a22e9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
33 changes: 21 additions & 12 deletions ptcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,60 @@

def main():
parser = argparse.ArgumentParser(description="Control PTCL router from command-line.")
parser.add_argument('-b', '--block', help="Block device.", nargs='?', default='cli')
parser.add_argument('-u', '--unblock', help="Unblock device.", nargs='?', default='cli')
parser.add_argument('-b', '--block', help="Block device.", default='.')
parser.add_argument('-u', '--unblock', help="Unblock device.", nargs='?')
parser.add_argument('-a', '--active-devices', help="Gets active devices number.", action='store_true')
parser.add_argument('-r', '--restart', help="Restart Router.", action='store_true')
parser.add_argument('-sd', '--show-dhcp', help='Show DHCP Info.', action='store_true')
parser.add_argument('-s', '--show-active', help='Show Active Devices.', default='.')
args = parser.parse_args()

print args
if args.block:
print "Calling blocker Function"
ptcl.get_sessionkey()
if args.block in my_macs.iterkeys():
print "Calling blocker Function"
ptcl.block_dev(my_macs[args.block.lower()])
print "%s has been blocked." % args.block.capitalize()

elif args.block == 'cli':
elif not args.block:
print "Calling blocker Function"
name = ptcl.show_active_dev()
dev_mac = int(raw_input("Please Enter Device Number: ")) - 1
ptcl.block_dev(ptcl.mac_and_host[name[dev_mac]])
print "%s has been blocked." % name[dev_mac].capitalize()

if args.unblock:
elif args.unblock:
print "Calling Unblocker Function"
ptcl.get_sessionkey()
if args.unblock in my_macs.iterkeys():
ptcl.unblock_dev(my_macs[args.unblock.lower()])
print "%s has been unblocked." % args.unblock
print "%s has been unblocked." % args.unblock.capitalize()

elif args.unblock == 'cli':
elif not args.unblock:
print "Calling unblocker Function"
name = ptcl.show_active_dev()
dev_mac = int(raw_input("Please Enter Device Number: ")) - 1
ptcl.unblock_dev(ptcl.mac_and_host[name[dev_mac]])
print "%s has been blocked." % name[dev_mac]
print "%s has been unblocked." % name[dev_mac].capitalize()

if args.active_devices:
elif args.active_devices:
print "Calling Station info Function"
ptcl.get_stationinfo()
print "Currently active devices are:", len(ptcl.active_dev)

if args.restart:
elif args.restart:
print "Calling restart Function"
ptcl.get_sessionkey()
ptcl.reboot_router()

if args.show_dhcp:
elif args.show_dhcp:
print "Calling DHCP_info Function"
ptcl.get_sessionkey()
ptcl.show_dhcpinfo()

if args.show_active == '.':
elif args.show_active == '.':
print "Calling show_active Function"
ptcl.show_active_dev()

else:
Expand Down
12 changes: 10 additions & 2 deletions router.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def show_dhcpinfo(self):
self.get_dhcpinfo()
print "-" * 20 + "DHCP-INFO" + "-" * 20 + '\n'
for num, i in enumerate(zip(self.dev_hostname, self.mac_address), 1):
whitespace = 30 - len(i[0])
print "%s:%s\n" % (i[0], ' ' * whitespace + i[1].upper())
whitespace = 30 - len(i[0]) - len(str(num))
print "(%s) %s:%s\n" % (num, i[0], ' ' * whitespace + i[1].upper())
print "-" * 49


Expand Down Expand Up @@ -130,6 +130,14 @@ def unblock_dev(self, udevmac):
r, soup = self.scrape_page(self.mask + "wlmacflt.cmd?action=remove&rmLst=%s&sessionKey=%s" % (udevmac, self.session_key))


def show_blocked_dev(self):
pass


def set_hostname(self):
pass


def hh_to_HH(self, time):
'''
Converts 12 hours format to 24 hours.
Expand Down

0 comments on commit 10a22e9

Please sign in to comment.