Skip to content

Commit

Permalink
Added Macs
Browse files Browse the repository at this point in the history
  • Loading branch information
RafayGhafoor committed Jul 23, 2017
1 parent 7520c51 commit 78b6b38
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 7 additions & 5 deletions ptcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def main():
parser = argparse.ArgumentParser(description="Control PTCL router from command-line.")
parser.add_argument('-b', '--block', help="Block device.")
parser.add_argument('-u', '--unblock', help="Unblock device.")
parser.add_argument('-r', '--restart', help="Restart Router.")
parser.add_argument('-sd', '--show-dhcp', help='Show DHCP Info.')
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()

Expand All @@ -18,7 +18,7 @@ def main():
ptcl.block_dev(ptcl.mac_and_host[name[dev_mac]], ptcl.get_sessionkey())

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

Expand All @@ -28,11 +28,13 @@ def main():
elif args.show_dhcp:
ptcl.show_dhcpinfo()

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

else:
print "Invalid Argument"


import time
start_time = time.time()
main()
print("--- %s seconds ---" % (time.time() - start_time))
14 changes: 10 additions & 4 deletions router.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@
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"}
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):
'''
A PTCL router class.
'''
macAddress_regex = re.compile(r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$')
mac_adr_regex = re.compile(r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$')


def __init__(self, mask="http://192.168.1.1", username="admin", password="admin"):
Expand Down Expand Up @@ -53,7 +59,7 @@ def get_dhcpinfo(self):
count = 1
td = soup.findAll('td')
for i in td:
if self.macAddress_regex.search(i.text):
if self.mac_adr_regex.search(i.text):
'''
The HTML page contains hostnames and mac addresses right next
to each other in the form of table. We search in the tables list
Expand Down Expand Up @@ -83,7 +89,7 @@ def get_stationinfo(self):
pass
for found in soup.findAll('td'):
if "PTCL-BB" not in found.text and "Yes" not in found.text and "wl0" not in found.text\
and self.macAddress_regex.search(found.text.strip()) != None:
and self.mac_adr_regex.search(found.text.strip()) != None:
self.active_dev.append(found.text.strip().lower().encode('ascii'))


Expand Down

0 comments on commit 78b6b38

Please sign in to comment.