Skip to content

Commit

Permalink
Added feature to block user by specifying their pre-defined names'
Browse files Browse the repository at this point in the history
  • Loading branch information
RafayGhafoor committed Jul 23, 2017
1 parent 0188382 commit 61892aa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
55 changes: 40 additions & 15 deletions ptcl.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,67 @@
from router import Router
import argparse
my_macs = {
"mytab": "5c:2e:59:4d:33:67",
"ahmer": "68:94:23:AC:59:51",
"asad": "A0:32:99:AB:33:31",
"hhp": "44-1C-A8-73-A3-17",
"j7": "",
"xperia": "",
"haris": "",
"i3": "",
"n4050": ""
}

ptcl = Router()


def main():
parser = argparse.ArgumentParser(description="Control PTCL router from command-line.")
parser.add_argument('-b', '--block', help="Block device.")
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('-a', '--active-devices', help="Gets active devices number.", action='store_true')
parser.add_argument('-u', '--unblock', help="Unblock device.")
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()

if args.block:
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]])
ptcl.get_sessionkey()
if args.block in my_macs.iterkeys():
ptcl.block_dev(my_macs[args.block.lower()])
print "%s has been blocked." % args.block.capitalize()

elif args.block == 'cli':
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:
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

elif args.unblock == 'cli':
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]

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

elif args.unblock:
name = ptcl.show_active_dev()
udev_mac = raw_input("Please Enter Device Number: ").upper()
ptcl.unblock_dev(ptcl.mac_and_host[name[udev_mac]])

elif args.restart:
if args.restart:
ptcl.get_sessionkey()
ptcl.reboot_router()

elif args.show_dhcp:
if args.show_dhcp:
ptcl.get_sessionkey()
ptcl.show_dhcpinfo()

elif args.show_active == '.':
ptcl.get_sessionkey()
if args.show_active == '.':
ptcl.show_active_dev()

else:
Expand Down
9 changes: 0 additions & 9 deletions router.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
import re
import sys

mymacs = {
"Samsung Galaxy Tab": "5c:2e:59:4d:33:67",
"Ahmer": "68:94:23:AC:59:51",
"Asad": "A0:32:99:AB:33:31",
"HP-i5": "44-1C-A8-73-A3-17"
}


class Router(object):
'''
Expand Down Expand Up @@ -128,15 +121,13 @@ def block_dev(self, devmac):
Block device using Mac Address.
'''
r, soup = self.scrape_page(self.mask + "wlmacflt.cmd?action=add&wlFltMacAddr=%s&sessionKey=%s" % (devmac, self.session_key))
print "Blocked."


def unblock_dev(self, udevmac):
'''
Unblock device using Mac Address.
'''
r, soup = self.scrape_page(self.mask + "wlmacflt.cmd?action=remove&rmLst=%s&sessionKey=%s" % (udevmac, self.session_key))
print "Unblocked."


def hh_to_HH(self, time):
Expand Down

0 comments on commit 61892aa

Please sign in to comment.